Package java.util.zip
Class CheckedInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.CheckedInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
public class CheckedInputStream extends FilterInputStream
The
CheckedInputStream class is used to maintain a checksum at the
same time as the data, on which the checksum is computed, is read from a
stream. The purpose of this checksum is to establish data integrity,
comparing the computed checksum against a published checksum value.-
Field Summary
Fields inherited from class java.io.FilterInputStream
in -
Constructor Summary
Constructors Constructor Description CheckedInputStream(InputStream is, Checksum csum)Constructs a newCheckedInputStreamonInputStreamis. -
Method Summary
Modifier and Type Method Description ChecksumgetChecksum()Returns the checksum calculated on the stream read so far.intread()Reads one byte of data from the underlying input stream and updates the checksum with the byte data.intread(byte[] buffer, int byteOffset, int byteCount)Reads up tobyteCountbytes of data from the underlying input stream, storing it intobuffer, starting at offsetbyteOffset.longskip(long byteCount)Skip up tobyteCountbytes of data on the underlying input stream.Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, resetMethods inherited from class java.io.InputStream
read
-
Constructor Details
-
CheckedInputStream
Constructs a newCheckedInputStreamonInputStreamis. The checksum will be calculated using the algorithm implemented bycsum.Warning: passing a null source creates an invalid
CheckedInputStream. All operations on such a stream will fail.- Parameters:
is- the input stream to calculate checksum from.csum- an entity implementing the checksum algorithm.
-
-
Method Details
-
read
Reads one byte of data from the underlying input stream and updates the checksum with the byte data.- Overrides:
readin classFilterInputStream- Returns:
-1at the end of the stream, a single byte value otherwise.- Throws:
IOException- if anIOExceptionoccurs.
-
read
Reads up tobyteCountbytes of data from the underlying input stream, storing it intobuffer, starting at offsetbyteOffset. The checksum is updated with the bytes read. Returns the number of bytes actually read or-1if arrived at the end of the filtered stream while reading the data.- Overrides:
readin classFilterInputStream- Throws:
IOException- if this stream is closed or some I/O error occurs.
-
getChecksum
Returns the checksum calculated on the stream read so far. -
skip
Skip up tobyteCountbytes of data on the underlying input stream. Any skipped bytes are added to the running checksum value.- Overrides:
skipin classFilterInputStream- Parameters:
byteCount- the number of bytes to skip.- Returns:
- the number of bytes skipped.
- Throws:
IOException- if this stream is closed or another I/O error occurs.- See Also:
FilterInputStream.mark(int),FilterInputStream.reset()
-