Piped input and output streams are convenient for methods that produce output to be used as input by someone else. For example, suppose that you are writing a class that implements various text utilities such as sorting and reversing text. It would be nice if the output of one of these methods could be used as the input for another so you could string a series of these methods together to perform some function. The main method provides the code for the main program, which opens an input file, uses the other two methods to reverse, sort, and reverse the words in the input file, and then writes the results to the standard output stream. Working with Filtered Streams talks about this.
Next reverse creates a PipedOutputStream and connects a PipedInputStream to it.
Remember that a PipedOutputStream must be connected to a PipedInputStream . Then reverse maps a PrintStream onto the PipedOutputStream so that it can use the PrintStream 's println method to write strings to the PipedOutputStream . Because the PipedOutputStream is connected to the PipedInputStream , all data written to the PipedOutputStream flows into the PipedInputStream . The data can be read from the PipedInputStream by another program or thread. Connect piped input stream to it.