Fabian Barney Fabian Barney - 5 months ago 11
Java Question

Chunkwise-Copy data from InputStream to OutputStream + getting byte[] at the end

I know how to copy chunkwise from an

InputStream
to an
OutputStream
.

I know how to get an
byte[]
from an
InputStream
.

But how to combine them in one step? Is there an OutputStream that can be piped and buffers all written bytes so it can return a byte[] at the end?

I need something like an
ByteArrayOutputStream
but one that can be piped. (e.g. to a FileOutputStream)

Or I need something like a
MultiOutputStream
which can forward to multiple OutputStreams.
Solutions using Guava and/or Apache Commons are prefered. :)

Answer
Comments