public static class ChecksumInputStream.Builder extends AbstractStreamBuilder<ChecksumInputStream,ChecksumInputStream.Builder>
ChecksumInputStream.
There is no default Checksum; you MUST provide one.
ChecksumInputStream s = ChecksumInputStream.builder()
.setPath(Paths.get("MyFile.xml"))
.setChecksum(new CRC32())
.setExpectedChecksumValue(12345)
.get();
ChecksumInputStream s = ChecksumInputStream.builder()
.setFile(new File("MyFile.xml"))
.setChecksum(new CRC32())
.setExpectedChecksumValue(12345)
.get();
The following validates the first 100 bytes of the given input.
ChecksumInputStream s = ChecksumInputStream.builder()
.setPath(Paths.get("MyFile.xml"))
.setChecksum(new CRC32())
.setExpectedChecksumValue(12345)
.setCountThreshold(100)
.get();
To validate input after the beginning of a stream, build an instance with an InputStream starting where you want to validate.
InputStream inputStream = ...;
inputStream.read(...);
inputStream.skip(...);
ChecksumInputStream s = ChecksumInputStream.builder()
.setInputStream(inputStream)
.setChecksum(new CRC32())
.setExpectedChecksumValue(12345)
.setCountThreshold(100)
.get();
get()| Modifier and Type | Field and Description |
|---|---|
private java.util.zip.Checksum |
checksum
There is no default checksum, you MUST provide one.
|
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 value once the stream is exhausted or the count threshold is reached. |
| Constructor and Description |
|---|
Builder() |
| Modifier and Type | Method and Description |
|---|---|
ChecksumInputStream |
get()
Builds a new
ChecksumInputStream. |
ChecksumInputStream.Builder |
setChecksum(java.util.zip.Checksum checksum)
Sets the Checksum.
|
ChecksumInputStream.Builder |
setCountThreshold(long countThreshold)
Sets the count threshold to limit how much input is consumed to update the
Checksum before the input
stream validates its value. |
ChecksumInputStream.Builder |
setExpectedChecksumValue(long expectedChecksumValue)
The expected
Checksum value once the stream is exhausted or the count threshold is reached. |
getBufferSize, getBufferSizeDefault, getCharSequence, getCharset, getCharsetDefault, getInputStream, getOpenOptions, getOutputStream, getPath, getReader, getWriter, setBufferSize, setBufferSize, setBufferSizeChecker, setBufferSizeDefault, setBufferSizeMax, setCharset, setCharset, setCharsetDefault, setOpenOptionscheckOrigin, getOrigin, hasOrigin, newByteArrayOrigin, newCharSequenceOrigin, newFileOrigin, newFileOrigin, newInputStreamOrigin, newOutputStreamOrigin, newPathOrigin, newPathOrigin, newReaderOrigin, newURIOrigin, newWriterOrigin, setByteArray, setCharSequence, setFile, setFile, setInputStream, setOrigin, setOutputStream, setPath, setPath, setReader, setURI, setWriterasThisclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitasSupplierprivate java.util.zip.Checksum checksum
Checksum
being proven deficient or insecure in the future.private long countThreshold
Checksum before the input
stream validates its value.
By default, all input updates the Checksum.
private long expectedChecksumValue
Checksum value once the stream is exhausted or the count threshold is reached.public ChecksumInputStream get() throws java.io.IOException
ChecksumInputStream.
You must set input that supports AbstractStreamBuilder.getInputStream(), otherwise, this method throws an exception.
This builder use the following aspects:
AbstractStreamBuilder.getInputStream()Checksumjava.lang.IllegalStateException - if the origin is null.java.lang.UnsupportedOperationException - if the origin cannot be converted to an InputStream.java.io.IOException - if an I/O error occurs.AbstractStreamBuilder.getInputStream()public ChecksumInputStream.Builder setChecksum(java.util.zip.Checksum checksum)
checksum - the Checksum.public ChecksumInputStream.Builder setCountThreshold(long countThreshold)
Checksum before the input
stream validates its value.
By default, all input updates the Checksum.
countThreshold - the count threshold. A negative number means the threshold is unbound.public ChecksumInputStream.Builder setExpectedChecksumValue(long expectedChecksumValue)
Checksum value once the stream is exhausted or the count threshold is reached.expectedChecksumValue - The expected Checksum value.