Class CheckedInputStream

All Implemented Interfaces:
Closeable, AutoCloseable

public class CheckedInputStream extends FilterInputStream
InputStream that computes a checksum of the data being read using a supplied Checksum object.
See Also:
  • Field Details

    • sum

      private final Checksum sum
      The checksum object.
  • Constructor Details

    • CheckedInputStream

      public CheckedInputStream(InputStream in, Checksum sum)
      Creates a new CheckInputStream on top of the supplied OutputStream using the supplied Checksum.
  • Method Details

    • getChecksum

      public Checksum getChecksum()
      Returns the Checksum object used. To get the data checksum computed so far call getChecksum.getValue().
    • read

      public int read() throws IOException
      Reads one byte, updates the checksum and returns the read byte (or -1 when the end of file was reached).
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] buf, int off, int len) throws IOException
      Reads at most len bytes in the supplied buffer and updates the checksum with it. Returns the number of bytes actually read or -1 when the end of file was reached.
      Overrides:
      read in class FilterInputStream
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Skips n bytes by reading them in a temporary buffer and updating the the checksum with that buffer. Returns the actual number of bytes skiped which can be less then requested when the end of file is reached.
      Overrides:
      skip in class FilterInputStream
      Throws:
      IOException