Re: Fastest way of combining byte arrays of different lengths?
From: Jon A. Cruz (jon_at_joncruz.org)
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
> 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
Then look at ByteArrayOutputStream.
But just setting the size on the BufferedInputStream and tuning your
sleep a little might give you the best performance.