public class CheckedInputStream extends FilterInputStream
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.in| Constructor and Description |
|---|
CheckedInputStream(InputStream is,
Checksum csum)
Constructs a new
CheckedInputStream on InputStream
is. |
| Modifier and Type | Method and Description |
|---|---|
Checksum |
getChecksum()
Returns the checksum calculated on the stream read so far.
|
int |
read()
Reads one byte of data from the underlying input stream and updates the
checksum with the byte data.
|
int |
read(byte[] buffer,
int byteOffset,
int byteCount)
Reads up to
byteCount bytes of data from the underlying input stream, storing it
into buffer, starting at offset byteOffset. |
long |
skip(long byteCount)
Skip up to
byteCount bytes of data on the underlying input
stream. |
available, close, mark, markSupported, resetnullInputStream, read, readAllBytes, readNBytes, readNBytes, transferTopublic CheckedInputStream(InputStream is, Checksum csum)
CheckedInputStream on InputStream
is. The checksum will be calculated using the algorithm
implemented by csum.
Warning: passing a null source creates an invalid
CheckedInputStream. All operations on such a stream will fail.
is - the input stream to calculate checksum from.csum - an entity implementing the checksum algorithm.public int read()
throws IOException
read in class FilterInputStream-1 at the end of the stream, a single byte value
otherwise.IOException - if an IOException occurs.public int read(byte[] buffer,
int byteOffset,
int byteCount)
throws IOException
byteCount bytes of data from the underlying input stream, storing it
into buffer, starting at offset byteOffset. The checksum is
updated with the bytes read.
Returns the number of bytes actually read or -1 if arrived at the
end of the filtered stream while reading the data.read in class FilterInputStreamIOException - if this stream is closed or some I/O error occurs.public Checksum getChecksum()
public long skip(long byteCount)
throws IOException
byteCount bytes of data on the underlying input
stream. Any skipped bytes are added to the running checksum value.skip in class FilterInputStreambyteCount - the number of bytes to skip.IOException - if this stream is closed or another I/O error occurs.FilterInputStream.mark(int),
FilterInputStream.reset()