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. 🙂
You should probably have a look at the
TeeOutputStreamof Apache: https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/output/TeeOutputStream.html