The whole point of StAX2 is that you do not need to read the file in memory. You can simply provide the source and let StAX StreamReader retrieve the data as needed.
What additional restrictions do you have that you do not see in your question?
If you have a lot of memory and want to get good performance, just wrap your InputStream with a large byte buffer and let the buffer do the buffering for you:
// 4 meg buffer on the stream InputStream buffered = new BufferedInputStream(schemaInputStream, 1024 * 1024 * 4);
An alternative to solving this in Java is to create a RAMDisk and save a file on it, which will fix the problem with Java, where the main limitation is that you can only have values ββless than Integer.MAX_VALUE in one array.
rolfl source share