Java Reference
In-Depth Information
performed through a stream abstraction. (Random-access file I/O is performed
with the
RandomAccessFile
class, but sequential I/O is much more common.)
A
str eam
is simply an object from which data can be read sequentially or to which
data can be written sequentially. The bulk of the
java.io
package consists stream
classes: there are 40 of them.
InputStream
and
OutputStream
and their respective
subclasses are objects for reading and writing streams of bytes, while
Reader
and
Writer
and their subclasses are objects for reading and writing streams of Unicode
characters. In addition to these stream classes, the
java.util.zip
package defines
another eight input and output byte streams for data compression and decompres-
sion. Table 3-1 through Table 3-4 summarize the stream classes available in
java.io
and
java.util.zip
.
Table 3−1. Byte Input Streams
Byte Input Stream
Description
Reads a buffer of bytes from an
InputStream
, and
then returns bytes from the buffer, making small
reads more efficient.
BufferedInputStream
Reads bytes sequentially from an array.
ByteArrayInputStream
This
java.util.zip
class computes a checksum of
the bytes it reads from an
InputStream
.
CheckedInputStream
Reads binary representations of Java primitive types
from an
InputStream
.
DataInputStream
Reads bytes sequentially from a file.
FileInputStream
The superclass of byte input stream filter classes.
FilterInputStream
This
java.util.zip
class uncompresses GZIP-
compressed bytes it reads from an
InputStream
.
GZIPInputStream
The superclass of
GZIPInputStream
and
ZipInputStream
.
InflaterInputStream
The superclass of all byte input streams.
InputStream
This class is deprecated as of Java 1.1; use
LineNumberReader
instead.
LineNumberInputStream
Reads binary representations of Java objects and
primitive values from a byte stream. This class is
used for the deserialization of objects.
ObjectInputStream
Reads bytes written to the
PipedOutputStream
to
which it is connected. Used in multithreaded
programs.
PipedInputStream
Adds a fixed-size pushback buffer to an input
stream, so that bytes can be unread. Useful with
some parsers.
PushbackInputStream
Reads bytes sequentially from two or more input
streams, as if they were a single stream.
SequenceInputStream