Class ChecksumVerifyingInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.compress.utils.ChecksumVerifyingInputStream
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
CRC32VerifyingInputStream

public class ChecksumVerifyingInputStream extends FilterInputStream
Verifies the checksum of the data read once the stream is exhausted.
Since:
1.7
  • Field Details

    • bytesRemaining

      private long bytesRemaining
    • expectedChecksum

      private final long expectedChecksum
    • checksum

      private final Checksum checksum
  • Constructor Details

    • ChecksumVerifyingInputStream

      public ChecksumVerifyingInputStream(Checksum checksum, InputStream in, long size, long expectedChecksum)
      Constructs a new instance.
      Parameters:
      checksum - Checksum implementation.
      in - the stream to wrap
      size - the of the stream's content
      expectedChecksum - the expected checksum
  • Method Details

    • getBytesRemaining

      public long getBytesRemaining()
      Returns:
      bytes remaining to read
      Since:
      1.21
    • read

      public int read() throws IOException
      Reads a single byte from the stream
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException - if the underlying stream throws or the stream is exhausted and the Checksum doesn't match the expected value
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Reads from the stream into a byte array.
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException - if the underlying stream throws or the stream is exhausted and the Checksum doesn't match the expected value
    • skip

      public long skip(long n) throws IOException
      Overrides:
      skip in class FilterInputStream
      Throws:
      IOException
    • verify

      private void verify() throws IOException
      Throws:
      IOException