org.apache.commons.compress.utils

## Class ChecksumVerifyingInputStream

- java.lang.Object
- - java.io.InputStream
  - - org.apache.commons.compress.utils.ChecksumVerifyingInputStream

- All Implemented Interfaces:
    Closeable, AutoCloseable
  Direct Known Subclasses:
    CRC32VerifyingInputStream

      public class ChecksumVerifyingInputStream
      extends InputStream

  A stream that verifies the checksum of the data read once the stream is exhausted.
  Since:
    1.7
  This class is not thread-safe

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ChecksumVerifyingInputStream(Checksum checksum, InputStream in, long size, long expectedChecksum)` Constructs a new instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `long` | `getBytesRemaining()`
    `int` | `read()` Reads a single byte from the stream
    `int` | `read(byte[] b)` Reads a byte array from the stream
    `int` | `read(byte[] b, int off, int len)` Reads from the stream into a byte array.
    `long` | `skip(long n)`

    - ### Methods inherited from class java.io.InputStream

      `available, mark, markSupported, reset`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### 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 Detail

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Overrides:
        `close` in class `InputStream`
      Throws:
        `IOException`

    - #### 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
      Specified by:
        `read` in class `InputStream`
      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)
                   throws IOException

      Reads a byte array from the stream
      Overrides:
        `read` in class `InputStream`
      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 `InputStream`
      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 `InputStream`
      Throws:
        `IOException`

Copyright © 2002–2022 The Apache Software Foundation. All rights reserved.