Re: Fastest way of combining byte arrays of different lengths?

From: Jon A. Cruz (jon_at_joncruz.org)
Date: 03/23/04


Date: Tue, 23 Mar 2004 09:17:25 -0800

Princess Morgiah wrote:
> I'm trying to download chunks off of a Socket, and return them as a single
> byte array. At the moment I store all the chunks in a Vector, calculate the
> total length, reserve that amount of bytes in a new buffer and fill the
> buffer.
>
> It works, but it's only a temporary solution - not clean, and especially not
> fast (+100ms for a few 100k bytes).
>

Well... first of all for speed, be sure to wrap your input stream in a
BufferedInputStream.

Then look at ByteArrayOutputStream.

But just setting the size on the BufferedInputStream and tuning your
sleep a little might give you the best performance.



Relevant Pages

  • Re: Hex Data to Serial Port
    ... Thank you for your replies, In specific I have to send typically 6-8 ... bytes of data which I am trying to store in a buffer as array. ...
    (microsoft.public.vc.mfc)
  • Fastest way of combining byte arrays of different lengths?
    ... single new byte array? ... I'm trying to download chunks off of a Socket, and return them as a single ... reserve that amount of bytes in a new buffer and fill the ... Can somebody recommend me a faster way of doing this? ...
    (comp.lang.java.help)
  • Re: software design question
    ... buffer for it though. ... Or store the strings in an array because ... I was only talking about storing the strings *to print later* in an array, ...
    (comp.lang.perl.misc)
  • how to deconcatenate
    ... what should i do to store some array in a buffer and then delete them randomly ... and now i want to delete data2 from buffer ... ...
    (comp.soft-sys.matlab)
  • PKWARE DCL-compatible compressor and decompressor (based on Ben Rudiak-Goulds information)
    ... /* being able to compress as well as PKWARE Data Compression library, ... // Size of output buffer, ... // Store the current size of output ...
    (comp.compression)