java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.CheckedInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
public class CheckedInputStream extends FilterInputStream
An input stream that also maintains a checksum of the data being read.
The checksum can then be used to verify the integrity of the input data.
- Since:
- 1.1
- See Also:
Checksum
-
Field Summary
-
Constructor Summary
Constructors Constructor Description CheckedInputStream(InputStream in, Checksum cksum)Creates an input stream using the specified Checksum. -
Method Summary
Modifier and Type Method Description ChecksumgetChecksum()Returns the Checksum for this input stream.intread()Reads a byte.intread(byte[] buf, int off, int len)Reads into an array of bytes.longskip(long n)Skips specified number of bytes of input.Methods declared in class java.io.FilterInputStream
available, close, mark, markSupported, read, resetMethods declared in class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
CheckedInputStream
Creates an input stream using the specified Checksum.- Parameters:
in- the input streamcksum- the Checksum
-
-
Method Details
-
read
Reads a byte. Will block if no input is available.- Overrides:
readin classFilterInputStream- Returns:
- the byte read, or -1 if the end of the stream is reached.
- Throws:
IOException- if an I/O error has occurred- See Also:
FilterInputStream.in
-
read
Reads into an array of bytes. Iflenis not zero, the method blocks until some input is available; otherwise, no bytes are read and0is returned.- Overrides:
readin classFilterInputStream- Parameters:
buf- the buffer into which the data is readoff- the start offset in the destination arrayblen- the maximum number of bytes read- Returns:
- the actual number of bytes read, or -1 if the end of the stream is reached.
- Throws:
NullPointerException- Ifbufisnull.IndexOutOfBoundsException- Ifoffis negative,lenis negative, orlenis greater thanbuf.length - offIOException- if an I/O error has occurred- See Also:
FilterInputStream.in
-
skip
Skips specified number of bytes of input.- Overrides:
skipin classFilterInputStream- Parameters:
n- the number of bytes to skip- Returns:
- the actual number of bytes skipped
- Throws:
IOException- if an I/O error has occurred- See Also:
InputStream.skipNBytes(long)
-
getChecksum
Returns the Checksum for this input stream.- Returns:
- the Checksum value
-