Why so difficult to pass the data?

"From InputStream to OutputStream it's so easy, but i can't find anything the other way round."

You can think to InputStreams as a "tap" for your data, and OutputStreams as a sink. Water flows naturally from the tap to the sink, as your application naturally processes data from an InputStream and saves to an OutputStream. If you have no special processing to do it's just one line of commons-io: org.apache.commons.io.IOUtils.copy(InputStream is, OutputStream os), is a single method, single thread.

Now imagine somebody is already throwing the water into the sink, and you want to use that water again. Either you need a vase (a buffer) or you have to use a pump (a thread) to bring the water up again.

Speaking in java you have a library that ask you an OutputStream to write the data and a second class that wants to process the results from the previous write from an InputStream:

   OutputStream out = ?; //what to put here?
   InputStream in = ?;


Home Basic concepts

Implementations Next