J2EEOnline J2EE 

Java Streams   «Prev  Next»
Lesson 1

Introduction to 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:
  1. How DataInputStreams and DataOutputStreams let you read and write numeric data
  2. How to buffer streams for improved performance with the BufferedInputStream and BufferedOutputStream classes
  3. How to connect input and output streams with the PipedStream class and to connect multiple input streams with the SequenceInputStream class
  4. How to read and write byte arrays through the streams mechanism with the ByteArrayInputStream and ByteArrayOutputStream classes

InputStream and OutputStream

InputStream and OutputStream are fairly raw classes and they read and write bytes singly or in groups.
Deciding what those bytes mean is completely up to the programmer and the code. However, there are certain extremely common data formats that can benefit from a solid implementation in the class library. For example, many integers passed as parts of network protocols are 32-bit big-endian integers.
Much of the text sent over the Web is either 7-bit ASCII, 8-bit Latin-1, or multibyte UTF-8. Many files transferred by FTP are stored in the ZIP format. Java provides a number of filter classes you can attach to raw streams to translate the raw bytes to and from these and other formats. The filters come in two versions:
  1. the filter streams, and
  2. the readers and writers.
The filter streams still work primarily with raw data as bytes: for instance, by compressing the data or interpreting it as binary numbers.
The readers and writers handle the special case of text in a variety of encodings such as UTF-8 and ISO 8859-1. Filters are organized in a chain and each link in the chain receives data from the previous filter or stream and passes the data along to the next link in the chain.