public class CheckedInputStream extends FilterInputStream
CheckedInputStreamclass 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.
|Constructor and Description|
Constructs a new
|Modifier and Type||Method and Description|
Returns the checksum calculated on the stream read so far.
Reads one byte of data from the underlying input stream and updates the checksum with the byte data.
Reads up to n bytes of data from the underlying input stream, storing it into
Skip up to
public CheckedInputStream(InputStream is, Checksum csum)
is. The checksum will be calculated using the algorithm implemented by
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
public int read(byte buf, int off, int nbytes) throws IOException
buf, starting at offset
off. The checksum is updated with the bytes read.
buf- the byte array in which to store the bytes read.
off- the initial position in
bufto store the bytes read from this stream.
nbytes- the maximum number of bytes to store in
-1if arrived at the end of the filtered stream while reading the data.
IOException- if this stream is closed or some I/O error occurs.
public Checksum getChecksum()
public long skip(long byteCount) throws IOException
byteCountbytes of data on the underlying input stream. Any skipped bytes are added to the running checksum value.