Currently, I am writing xml file on local directory using XMLOutputFactory
which accept OutputStream
as a parameter. But Now I need to write xml file to AWS S3 without writing on local. I don't have local directory access.
But I am not getting "How I can write xml file to AWS S3?".
Here is my code which write xml in local directory.
File file = new File(storeFilename);
DataOutputStream stream = null;
stream = new DataOutputStream(new FileOutputStream(file));
// Create new instance of XML straem writer
XMLOutputFactory inputFactory = XMLOutputFactory.newInstance();
try {
XMLStreamWriter writer = inputFactory.createXMLStreamWriter(
graphMLOutputStream, "UTF8");
writer.writeStartDocument();
writer.writeStartElement(GRAPHML);
writer.writeAttribute(XMLNS, GRAPHML_XMLNS);
}
I know how to put files on AWS S3 using PutObjectRequest()
by giving file name or inputstream as a parameter.
// send request to S3 to create folder
PutObjectRequest putobjreq = new PutObjectRequest(
CAWSConstants.BUCKETNAME, file.getName(), file);
// put graphml file to aws
s3Client.putObject(putobjreq);
But I don't know how to covert xml in to inputstream using xmlWriter. Which I can sent to PutObjectRequest
.
Please give me hint or reference.