On Sat, Jul 01, 2000 at 05:48:08PM -0700, Jon Stevens wrote:
> essentially, i'm doing a servlet based proxy that will allow you to easily
> modify the headers and content going in and out through the proxy with regex
> and stuff. it is a pretty cool hack that we need implemented.

Sounds interesting - what are you planning to do with it?

> anyway, what i need now is a simple method to read all the bytes from an
> inputstream into a byte[]. the trick is that you don't know the length of
> data coming in from the stream (and thus cannot pre-allocate the byte[]) AND
> i want it to be a bit more efficient than simply reading a byte at a time
> with the read() method.

Write the data into a ByteArrayOutputStream, something like (where 'in'
is your InputStream):

ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] block = new byte[4096]; // for a 4k block size
int count;
while ((count = in.read(block) != -1)
{
    baos.write(block, 0, count);
}
baos.close();

byte[] data = baos.toByteArray();

-- 
Sean Legassick
[EMAIL PROTECTED]
                                  homo sum: humani nihil a me alienum puto



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to