This article, the second of two parts, continues to explain how to use streams with Java to interact with different storage devices. It is excerpted from chapter 15 of the book Sams Teach Yourself Java 2 in 21 days, written by Roger Cadenhead and Laura Lemay (Sams, ISBN: 0672326280).
Filtered streams are streams that modify the information sent through an existing stream. They are created using the subclasses FilterInputStream and FilterOutputStream.
These classes do not handle any filtering operations themselves. Instead, they have subclasses, such as BufferInputStream and DataOutputStream, that handle specific types of filtering.
Information is delivered more quickly if it can be sent in large chunks, even if those chunks are received faster than they can be handled.
As an example of this, consider which of the following book-reading techniques is faster:
A friend lends you a book in its entirety and you read it.
A friend lends you a book one page at a time and doesn't give you a new page until you have finished the previous one.
Obviously, the first technique is going to be faster and more efficient. The same benefits are true of buffered streams in Java.
A buffer is a storage place where data can be kept before it is needed by a program that reads or writes that data. By using a buffer, you can get data without always going back to the original source of the data.