What happens when you want to read in a InputStream (or Reader) every byte (or character) that is being written to an OutputStream (or Writer)?
That's what pipes are good for. You have one
thread procesing information, and writing that information into a PipeOutputStream (PipedWriter). At the other side of the pipe there is another thread, reading the information through a PipedInputStream (PipedReader).
For instance, you have this thread, that simply receives a list of
Strings, reverse them and then prints them on the screen.
Now, instead of printing them in the screen, we are going to send them on pipe
to other thread
You do that like this:
But, how do we connect the pipes?. That's to say, how do we make another thread to
receive the reversed strings. Well, take a look at this example. In this case, the
thread that connects to the other end of the pipe is the main thread.
I hope this helps!
[ April 27, 2006: Message edited by: Edwin Dalorzo ]