Writing XML Document to InputStream using dom4j

When tring to upload a XML file to AWS S3, I found that it’s not allowed to create a tmp file in server local, so I had to transfer the file as InputStream at first and upload it later.

This is the code of transfering the XML Document instance to InputStream and Byte array:

As dom4j is been used to generate the XML, some classes from which (e.g. Document, XMLWriter) can be found in the code.