java - BufferedReader for large ByteBuffer? -


Is there a way to read a bytebuffer without a bufferbringer starting a string in the first? I want to read through a large bitfuff in the form of text and avoid wanting to write it on disk for performance reasons Calling does not work to call the bytebuff because the resulting string is too large (this is java.lang. OutOfMemoryError: Java heap throws space). I would have thought that there would be anything in the API to wrap a bytebuffer in the appropriate reader, but I do not find anything suitable.

Here is a brief code sample that shows what I am doing:

input stream is input from the InputStream () public string read (InputStream istream) {ReadableByteChannel source = channel.new channel (istream); BytereoneOperfectTream Oostrum = New BytereonOperputstream (Buffer Size); WritableByteChannel Destination = Channel. New channel (ostream); Bytebuff buffer = bytefuffer.lookpoint (buffer size); While (source buffer)! = -1) {Buffer. Flip (); While (buffer HSRManning ()) {destination.write (buffer); } Buffer.clair (); } // This data can be up to 150 MB .. The string will not fit in the results = ostream.toString (); Source.close (); Destination.close (); Return result; } // Once the process has run, we call this method with the string public Odd redlines (string reader) (buffer reader = new bufftder (new string reader (text)); string line; while ((line = reader .Readline ())! = Null) {// stuff with line}}

It's not clear why you are using a byte buffer. If you've got a InputStream and you read lines for it If you want, why are not you wrapped in a InputStreamReader in a BufferedReader ?? What is the benefit of adding NIO?

Calling < A byteArrayOutputStream on code> toString () seems like a bad idea to me, even if you have the space: get it as a byte array and bypass it by ByteArrayInputStream Putting in and then in an InputStreamReader , if you actually have a ByteArrayOutputStream . If you actually call If you want to call toString () , use the minimum overload which takes the name of character encoding for use - otherwise this system will use the default, which is probably not Which you want.

EDIT: OK, so you really want to use NIO. If you are still writing on a BITTEROnAptStust , then you have a data with it in Baoos If you want to avoid making a copy of that data, you will need to get it from ByteArrayOutputStream , for example:

  public class readableByteArrayOutputStream ByteArrayOutputStream Extended / ** * data in the current stream BiteAreanInput transforms into stream * The resulting stream wraps directly to the existing byte array; * Next will be the result of unexpected * behavior while writing this output stream * / Public InputStream toInputStream (New ByteArrayInputStream (array, 0, counting); }}  

Then you can create the input stream, wrap it in the InputStreamReader , wrap it in a BufferedReader , again.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -