I'm working on an application that needs to move very large strings
around (XML files, several megabytes in length). I can't do anything
about the fact they're available to my program as Strings. It's just
the way the API I'm using works.
There are a couple of things I need to do with those strings: pass them
to a SAXParser (which expects an InputStream), and write them to files.
Problem is, no matter what I to do, the file ends up truncated (pretty
much always in the same location, toward the end of the file).
I've tried lots of things, including passing the string to a
StringReader and buffering it. I've also tried things like:
byte[] bytes = xmlDoc.getBytes();
InputStream bytestream = new ByteArrayInputStream(bytes);
and then writing it out to a Buffered writer with:
while ((nextChar = xmlDoc.read()) != -1)
Pretty much everything I do results in a truncated file.
Can anyone suggest a good general approach to dealing with large strings
(that need to turn into streams for writing or other reasons)?
Thanks,
Steve
--
Stephen Ramsay