Class ChecksumInputStream.Builder

All Implemented Interfaces:
IOSupplier<ChecksumInputStream>
Enclosing class:
ChecksumInputStream

public static class ChecksumInputStream.Builder extends AbstractStreamBuilder<ChecksumInputStream,ChecksumInputStream.Builder>
Builds a new ChecksumInputStream.

There is no default Checksum; you MUST provide one.

Using NIO


 ChecksumInputStream s = ChecksumInputStream.builder()
   .setPath(Paths.get("MyFile.xml"))
   .setChecksum(new CRC32())
   .setExpectedChecksumValue(12345)
   .get();
 

Using IO


 ChecksumInputStream s = ChecksumInputStream.builder()
   .setFile(new File("MyFile.xml"))
   .setChecksum(new CRC32())
   .setExpectedChecksumValue(12345)
   .get();
 

Validating only part of an InputStream

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();
 
See Also:
  • Field Details

    • checksum

      private Checksum checksum
      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.
    • countThreshold

      private long countThreshold
      The count threshold to limit how much input is consumed to update the Checksum before the input stream validates its value.

      By default, all input updates the Checksum.

    • expectedChecksumValue

      private long expectedChecksumValue
      The expected Checksum value once the stream is exhausted or the count threshold is reached.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details