|
Chapter 18 The java.util.zip Package |
|
CheckedInputStream
Name
CheckedInputStream
- Class Name:
-
java.util.zip.CheckedInputStream
- Superclass:
-
java.io.FilterInputStream
- Immediate Subclasses:
-
None
- Interfaces Implemented:
-
None
- Availability:
-
New as of JDK 1.1
The CheckedInputStream class
represents an InputStream with
an associated checksum. In other words, a CheckedInputStream
wraps a regular input stream and computes a checksum value as data is read
from the stream. The checksum can verify the integrity of the
data. When you create a CheckedInputStream,
you must specify an object that implements the Checksum
interface that computes the checksum.
public class java.util.zip.CheckedInputStream
extends java.io.FilterInputStream {
// Constructors
public CheckedInputStream(InputStream in, Checksum cksum);
// Instance Methods
public Checksum getChecksum();
public int read();
public int read(byte[] buf, int off, int len);
public long skip(long n);
}
- Parameters
-
- in
-
The underlying input stream to use as a data source.
- cksum
-
The checksum object.
- Description
-
This constructor creates a CheckedInputStream
that reads data from the given InputStream
and updates the given Checksum.
- Returns
-
The Checksum associated with
this input stream.
- Description
-
This method returns the Checksum
object associated with this input stream.
- Returns
-
The next byte from the stream or -1 if the end of the stream has been reached.
- Throws
-
- IOException
-
If any kind of I/O error occurs.
- Overrides
-
FilterInputStream.read()
- Description
-
This method reads the next byte from the underlying InputStream
and then updates the checksum. The method blocks until some data is available,
the end of the stream is detected, or an exception is thrown.
- Parameters
-
- buf
-
An array of bytes to be filled from the stream.
- off
-
An offset into the byte array.
- len
-
The number of bytes to read.
- Returns
-
The number of bytes read or -1 if the end of the stream is encountered
immediately.
- Throws
-
- IOException
-
If any kind of I/O error occurs.
- Overrides
-
FilterInputStream.read(byte[], int, int)
- Description
-
This method reads up to len
bytes from the underlying InputStream
and places them into the given array starting at off.
The checksum is then updated with the data that has been read. The method
blocks until some data is available.
- Parameters
-
- n
-
The number of bytes to skip.
- Returns
-
The actual number of bytes skipped.
- Throws
-
- IOException
-
If any kind of I/O error occurs.
- Overrides
-
FilterInputStream.skip()
- Description
-
This method skips over the specified number of bytes in the underlying
InputStream. The skipped bytes
are not calculated into the checksum.
Checksum,
FilterInputStream,
InputStream,
IOException
|
|