this failed. In what way? Did you get an error message? Was the data invalid? Something else?
Looks like the data is coming from a java.sql.Clob. Are you certain that an ascii stream will be appropriate? If the characters you're reading come from any non-English languages, you may need to use getCharacterStream() to read into a char[] array instead. (This will usually take take more memory, but it should work
correctly, which is probably more important.) If you're using a byte[] you need to know for sure what encoding is being used. If you don't, you may well get data that looks like it's corrupt gibbersh. So find out what the encoding realy is, or use getCharacterStream() instead.
If your probles are still with memory usage - first, are you sure you really need the whole object in memory at once? Formany applications, you can just read some data, process it, write it to a file or socket or DB or whatever, then read some more data. Keep looping until you're done. If you can organize the processing so this is possible, do it. If not, if you really need all the data in memory at once - well, for one thing you can save some space by knowing how big the byte[] or char[] array needs to be in the first pplace, and allocting it in advance. Then just read directly into the array, with no need for any other ByteArrayOutputStream or even BufferedInput/Output streams. (If you're using the preallocated array correctly, you're doing your own "buffering" at the final destination; the other buffers become redudant.) Here's what this can look like, using an ascii stream (where 1 byte = 1 character):
On completion, array should be filled with the data you read, and no extra objects were allocated. Or if you need to use character streams and chars:
This will take twice as much memory, but hey, at least it will be correct.
[ October 24, 2003: Message edited by: Jim Yingst ]