Use InputStream it presents a method called transferTo with the following impression:
public long transferTo(OutputStream out) throws IOException
From the documentation, transferTo will:
Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read. On return, this input stream will be at end of the stream. This method does not close either stream.
This method may block indefinitely reading from the input stream or writing to the output stream. The behavior for the case where the input and/or output stream is asynchronously closed or the thread interrupted during the transfer, highly inputs and output stream specific, and therefore not specified
So in order to reproduce contents of a Java InputStream to an OutputStream, you need to address: