public static class ChecksumInputStream.Builder extends ProxyInputStream.AbstractBuilder<ChecksumInputStream,ChecksumInputStream.Builder>
ChecksumInputStream.
There is no default Checksum; you MUST provide one. This avoids any issue with a default Checksum being proven deficient or insecure
in the future.
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()| Constructor and Description |
|---|
Builder()
Constructs a new builder of
ChecksumInputStream. |
| Modifier and Type | Method and Description |
|---|---|
ChecksumInputStream |
get()
Builds a new
ChecksumInputStream. |
ChecksumInputStream.Builder |
setChecksum(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. |
getAfterRead, setAfterReadgetBufferSize, getBufferSizeDefault, getCharSequence, getCharset, getCharsetDefault, getFile, getInputStream, getOpenOptions, getOutputStream, getPath, getRandomAccessFile, getReader, getWriter, setBufferSize, setBufferSize, setBufferSizeChecker, setBufferSizeDefault, setBufferSizeMax, setCharset, setCharset, setCharsetDefault, setOpenOptionscheckOrigin, getOrigin, hasOrigin, newByteArrayOrigin, newCharSequenceOrigin, newFileOrigin, newFileOrigin, newInputStreamOrigin, newOutputStreamOrigin, newPathOrigin, newPathOrigin, newRandomAccessFileOrigin, newRandomAccessFileOrigin, newReaderOrigin, newURIOrigin, newWriterOrigin, setByteArray, setCharSequence, setFile, setFile, setInputStream, setOrigin, setOutputStream, setPath, setPath, setRandomAccessFile, setRandomAccessFile, setReader, setURI, setWriterasThisclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitasSupplier, getUncheckedpublic Builder()
ChecksumInputStream.public ChecksumInputStream get() throws IOException
ChecksumInputStream.
You must set an aspect that supports AbstractStreamBuilder.getInputStream(), otherwise, this method throws an exception.
This builder uses the following aspects:
AbstractStreamBuilder.getInputStream() gets the target aspect.ChecksumIllegalStateException - if the origin is null.UnsupportedOperationException - if the origin cannot be converted to an InputStream.IOException - if an I/O error occurs converting to an InputStream using AbstractStreamBuilder.getInputStream().AbstractStreamBuilder.getInputStream(),
IOSupplier.getUnchecked()public ChecksumInputStream.Builder setChecksum(Checksum checksum)
Checksum, you MUST provide one. This avoids any issue with a default Checksum being proven
deficient or insecure in the future.checksum - the Checksum.this instance.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.this instance.public ChecksumInputStream.Builder setExpectedChecksumValue(long expectedChecksumValue)
Checksum value once the stream is exhausted or the count threshold is reached.expectedChecksumValue - The expected Checksum value.this instance.