public final class ChecksumInputStream extends CountingInputStream
Checksum value once the stream is exhausted or the count threshold is reached.
If the Checksum does not meet the expected value when exhausted, then the input stream throws an
IOException.
If you do not need the verification or threshold feature, then use a plain CheckedInputStream.
To build an instance, use ChecksumInputStream.Builder.
ChecksumInputStream.Builder| Modifier and Type | Class and Description |
|---|---|
static class |
ChecksumInputStream.Builder
Builds a new
ChecksumInputStream. |
| Modifier and Type | Field and Description |
|---|---|
private long |
countThreshold
The count threshold to limit how much input is consumed to update the
Checksum before the input stream
validates its value. |
private long |
expectedChecksumValue
The expected checksum.
|
| Modifier | Constructor and Description |
|---|---|
private |
ChecksumInputStream(java.io.InputStream in,
java.util.zip.Checksum checksum,
long expectedChecksumValue,
long countThreshold)
Constructs a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterRead(int n)
Adds the number of read bytes to the count.
|
static ChecksumInputStream.Builder |
builder()
Constructs a new
ChecksumInputStream.Builder. |
private java.util.zip.Checksum |
getChecksum()
Gets the current checksum value.
|
long |
getRemaining()
Gets the byte count remaining to read.
|
getByteCount, getCount, resetByteCount, resetCount, skipavailable, beforeRead, close, handleIOException, mark, markSupported, read, read, read, reset, unwrapprivate final long expectedChecksumValue
private final long countThreshold
Checksum before the input stream
validates its value.
By default, all input updates the Checksum.
private ChecksumInputStream(java.io.InputStream in,
java.util.zip.Checksum checksum,
long expectedChecksumValue,
long countThreshold)
in - the stream to wrap.checksum - a Checksum implementation.expectedChecksumValue - the expected checksum.countThreshold - the count threshold to limit how much input is consumed, a negative number means the
threshold is unbound.public static ChecksumInputStream.Builder builder()
ChecksumInputStream.Builder.ChecksumInputStream.Builder.protected void afterRead(int n)
throws java.io.IOException
CountingInputStreamafterRead in class CountingInputStreamn - number of bytes read, or -1 if no more bytes are availablejava.io.IOException - Not thrown here but subclasses may throw.private java.util.zip.Checksum getChecksum()
public long getRemaining()