Java Reference
In-Depth Information
CipherInputStream
Reads data from an encrypted input stream.
DigestInputStream
Reads data from an input stream and updates an associated
message digest. A message digest is a mechanism for combining
an arbitrary amount of data from a stream into a fixed length
value that can be used to verify the integrity of the data.
InflaterInputStream
Reads data from a stream that has been compressed, such as a
ZIP file for example.
LineNumberInputStream
Reads data from a stream and keeps track of the current line
number. The line number starts at 0 and is incremented each
time a newline character is read.
ProgressMonitorInput
Stream
Reads data from an input stream and uses a progress-monitor to
monitor reading the stream. If reading the stream takes a
significant amount of time, a progress dialog will be displayed
offering the option to cancel the operation. This is used in
window-based applications for operations that are expected to
be time consuming.
PushbackInputStream
Adds the capability to return the last byte that was read back to
the input stream so you can read it again.
You can create a BufferedInputStream object from any other input stream, since the constructor
accepts a reference of type InputStream as an argument. The BufferedInputStream class
overrides the methods inherited from InputStream . For instance, in the following example:
BufferedInputStream keyboard = new BufferedInputStream(System.in);
the argument, System.in , is the static member of the System class that encapsulates input from the
keyboard, and is of type InputStream . We will be looking into how we can best read input from the
keyboard a little later in this chapter.
The effect of wrapping a stream in a BufferedInputStream object is to buffer the underlying stream
in memory so that data can be read from the stream in large chunks - up to the size of the buffer
provided. The data is then made available to the read() methods directly from memory, only
executing a real read operation from the underlying stream when the buffer is empty. With a suitable
choice of buffer size, the number of input operations that are needed will be substantially reduced, and
the process will be a whole lot more efficient. The reason for this is that for most input streams, each
read operation carries quite a bit of overhead, beyond the time required to actually transfer the data. In
the case of a disk file for instance, the transfer of data from the disk to memory can only start once the
read/write head has been positioned over the track that contains the data and the disk has rotated to the
point where the read/write head is over the point in the track where the data starts. This delay before
the transfer of data begins will typically be several milliseconds and will often be much longer than the
time required to transfer the data. Thus by minimizing the number of separate read operations that are
necessary you can substantially reduce to total time needed to read a significant amount of data.
Search WWH ::




Custom Search