Java Reference
In-Depth Information
After you run this program, you can display the pic.gif file in any web browser or
graphics-editing tool. It's a small image file in the GIF format, as shown in Figure 15.1.
FIGURE 15.1
The pic.gif file
(enlarged).
15
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 sub-
classes, such as BufferInputStream and DataOutputStream, which 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:
A friend lends you a book in its entirety and you read it.
n
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.
n
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.
Buffered Streams
A buffered input stream fills a buffer with data that hasn't been handled yet. When a pro-
gram needs this data, it looks to the buffer first before going to the original stream
source.
 
Search WWH ::




Custom Search