org.apache.commons.compress.utils

## Class ChecksumCalculatingInputStream

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

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class ChecksumCalculatingInputStream
      extends InputStream

  A stream that calculates the checksum of the data read.
  Since:
    1.14
  This class is not thread-safe

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ChecksumCalculatingInputStream(Checksum checksum, InputStream inputStream)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `long` | `getValue()` Returns the calculated checksum.
    `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, close, mark, markSupported, reset`

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

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

- - ### Constructor Detail

    - #### ChecksumCalculatingInputStream

          public ChecksumCalculatingInputStream(Checksum checksum,
                                                InputStream inputStream)

  - ### Method Detail

    - #### getValue

          public long getValue()

      Returns the calculated checksum.
      Returns:
        the calculated checksum.

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