String max size for 722MB xml file



I have a ByteArrayOutputStream which holds a byte representation of an XML with 750MB size.


I need to convert it to String.


I wrote:



ByteArrayOutputStream xmlArchive = ...
String xmlAsString = xmlArchive.toString(UTF8);


However although I am using 4GB of heap size I get java.lang.OutOfMemoryError: Java heap space


What is wrong? How can I know which heap size to use? I am using JDK64 bit


UPDATE


I need it as String in order to remove all the characters before "


Currently my code is:



String xmlAsString = xmlArchive.toString(UTF8);
int xmlBegin = xmlAsString.indexOf("<?xml");
if (xmlBegin >0){
return xmlAsString.substring(xmlBegin);
}
return xmlAsString;


I then convert it again to byte array.


No comments:

Post a Comment