Class CheckedInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

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

      Fields 
      Modifier and Type Field Description
      private Checksum sum
      The checksum object.
      • Fields inherited from class java.io.FilterInputStream

        in
    • Constructor Summary

      Constructors 
      Constructor Description
      CheckedInputStream​(java.io.InputStream in, Checksum sum)
      Creates a new CheckInputStream on top of the supplied OutputStream using the supplied Checksum.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Checksum getChecksum()
      Returns the Checksum object used.
      int read()
      Reads one byte, updates the checksum and returns the read byte (or -1 when the end of file was reached).
      int read​(byte[] buf, int off, int len)
      Reads at most len bytes in the supplied buffer and updates the checksum with it.
      long skip​(long n)
      Skips n bytes by reading them in a temporary buffer and updating the the checksum with that buffer.
      • Methods inherited from class java.io.FilterInputStream

        available, close, mark, markSupported, read, reset
      • Methods inherited from class java.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • sum

        private final Checksum sum
        The checksum object.
    • Constructor Detail

      • CheckedInputStream

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

      • 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 java.io.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 java.io.FilterInputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] buf,
                        int off,
                        int len)
                 throws java.io.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 java.io.FilterInputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.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 java.io.FilterInputStream
        Throws:
        java.io.IOException