Fork me on GitHub

Java: Create an InputStream from an OutputStream

InputStream is;
OutputStream os;

// usage of the OutputStream...

byte[] buffer = new byte[os.size];
os.write(buffer, 0, os.size);

is = new ByteArrayInputStream(buffer);

The idea here is to copy the OutputStream content to a buffer, and then create an IntputStream that uses it as its buffer array.

Keep in mind that buffer is stored in memory.
The bigger is the buffer, the bigger is the memory usage.