You can also use the data output stream you will learn about in Section 20.6.2 on page 539 to write characters
as bytes using a specific Unicode encoding.
There is no ReaderInputStream class to translate characters to bytes, nor a WriterOutputStream
class to translate bytes to characters.
20.5. A Quick Tour of the Stream Classes
The java.io package defines several types of streams. The stream types usually have input/output pairs,
and most have both byte stream and character stream variants. Some of these streams define general
behavioral properties. For example:
Filter streams are abstract classes representing streams with some filtering operation applied as
data is read or written by another stream. For example, a FilterReader object gets input from
another Reader object, processes (filters) the characters in some manner, and returns the filtered
result. You build sequences of filtered streams by chaining various filters into one large filter. Output
can be filtered similarly (Section 20.5.2).
•
Buffered streams add buffering so that read and write need not, for example, access the file
system for every invocation. The character variants of these streams also add the notion of
line-oriented text (Section 20.5.3).
•
Piped streams are pairs such that, say, characters written to a PipedWriter can be read from a
PipedReader (Section 20.5.4).
•
A group of streams, called in-memory streams, allow you to use in-memory data structures as the source or
destination for a stream:
- ByteArray streams use a byte array (Section 20.5.5).
- CharArray streams use a char array (Section 20.5.6).
- String streams use string types (Section 20.5.7).
The I/O package also has input and output streams that have no output or input counterpart:
The Print streams provide print and println methods for formatting printed data in
human-readable text form (Section 20.5.8).
•
LineNumberReader is a buffered reader that tracks the line numbers of the input (characters only)
(Section 20.5.9).
•
SequenceInputStream converts a sequence of InputStream objects into a single
InputStream so that a list of concatenated input streams can be treated as a single input stream
(bytes only) (Section 20.5.10).
•
There are also streams that are useful for building parsers:
Pushback streams add a pushback buffer you can use to put back data when you have read too far
(Section 20.5.11).
•
The StreamTokenizer class breaks a Reader into a stream of tokensrecognizable "words" that
are often needed when parsing user input (characters only) (Section 20.5.12).
•
These classes can be extended to create new kinds of stream classes for specific applications.
Each of these stream types is described in the following sections. Before looking at these streams in detail,
however, you need to learn something about the synchronization behavior of the different streams.