Using Streams in Java
(Page 1 of 4 )
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).
Filtering a Stream
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.
Byte Filters
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:
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.
Next: Buffered Streams >>
More Java Articles
More By Sams Publishing
|
This article is excerpted from chapter 15 of Sams Teach Yourself Java 2 in 21 Days, written by Rogers Cadenhead and Laura Lemay (Sams; ISBN: 0672326280). Check it out today at your favorite bookstore. Buy this book now.
|
|