Lesson 1
Filtering Streams in Java
This module introduces you to streams that perform more complex operations on the bytes they read. Java provides efficient means to convert the appropriate number of bytes into an integer or a floating point number.
You will learn about the following:
- How DataInputStreams and DataOutputStreams let you read and write numeric data
- How to buffer streams for improved performance with the BufferedInputStream and BufferedOutputStream classes
- How to connect input and output streams with the PipedStream class and to connect multiple input streams with the SequenceInputStream class
- How to read and write byte arrays through the streams mechanism with the ByteArrayInputStream and ByteArrayOutputStream classes
Characteristics of Streams between Java 1.1 and Java 2
Filter input streams read data from a preexisting input stream like a FileInputStream and have an opportunity to work with or change the data before it is delivered to the client program. Filter output streams write data to a preexisting output stream such as a FileOutputStream and have an opportunity to work with or change the data before it is written onto the underlying stream. Multiple filters can be chained onto a single underlying stream. Filter streams are used for encryption, compression, translation and buffering.
The word filter is derived by analogy from a water filter. A water filter sits between the pipe and faucet, pulling out impurities. A stream filter sits between the source of the data and its eventual destination and applies a specific algorithm to the data.
As drops of water are passed through the water filter and modified, the bytes of data are passed through the stream filter.
Of course, there are some big difference most notably, a stream filter can add data or some other kind of annotation to the stream, in addition to removing things you do not want. It may even produce a stream that is completely different from its original input (for example, by compressing the original data).
InputStream and OutputStream
Ad Java Network Programming