So currently I am using XMLStreamReader to read through a file I have. In the file there are the tags <Data> ... </Data> . Within these tags is a huge amount of Base64 encoded data. The data can be as big as 20MB. I use XMLStreamReader to reach this <Data> tag and then I want to read the data in parts and write it to another file. I am basically transferring <Data> ... </Data> content to another file. How can I get the data in small parts from XMLStreamReader and write it to another file? Is it possible to couple XMLStreamReader with some form of InputStream and use byte[] of comfortable size? Below is my current code
Public void readXML(File file){
XMLInputFactory inpFac = XMLInputFactory.newInstance();
FileInputStream fin = new FileInputStream(tmpFile)
XMLStreamReader reader = inpFac.createXMLStreamReader(inputStream);
While(reader.hasNext())
{
If(reader.isStartElement() && reader.getName().getLocalPart().equals("Data")){
File imgFile=new File("img.txt");
try(FileWriter fw = new FileWriter(imgFile);){
fw.write(reader.getElementText());//need to avoid this , can't get all data at once
writer.flush();
}
}
Basically instead of doing reader.getElementText() I want to get the data in small portions (maybe by using Byte[]?). Is it possible to convert the XMLStreamReader to a BufferedReader and read line by line ? Is it possible to wrap BufferedReader around XMLStreamReader ? Please let me know how I can make the question better as I am new to SO