ChecksumInputStream (JHOVE Documentation)
Date: 2013-09-08

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.harvard.hul.ois.jhove
Class ChecksumInputStream

    java.lang.Object
      java.io.InputStream
          java.io.FilterInputStream
              edu.harvard.hul.ois.jhove.ChecksumInputStream

All Implemented Interfaces:
  java.io.Closeable

    public class ChecksumInputStream

extends java.io.FilterInputStream

A ChecksumInputStream is a FilterInputStream with the added functionality of calculating checksums as it goes. The idea of replacing this with java.util.zip.CheckedInputStream looks very tempting, but we need the byte count, which CheckedInputStream doesn't provide.

Author:
  Gary McGath

Field Summary

Fields inherited from class java.io.FilterInputStream
`in`

Constructor Summary
`ChecksumInputStream(java.io.InputStream stream, Checksummer cksummer)` Constructor.

Method Summary
`void` | `close()` Closes the subsumed stream.
`Checksummer` | `getChecksummer()` Returns the Checksummer object.
`long` | `getNBytes()` Returns the byte count to date on the stream.
`int` | `read()` Reads a byte from the subsumed stream, updating the byte count and the checksums.
`int` | `read(byte[] b)` Reads some number of bytes from the input stream and stores them into the buffer array b.
`int` | `read(byte[] b, int off, int len)` Reads up to len bytes of data from the input stream into an array of bytes.
`long` | `skip(long n)` Skips n bytes.

Methods inherited from class java.io.FilterInputStream
`available, mark, markSupported, reset`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ChecksumInputStream

    public ChecksumInputStream(java.io.InputStream stream,
                               Checksummer cksummer)

  Constructor.

  Parameters:
    `stream` - Stream to be filtered
    `cksummer` - Object to calculate checksum on the bytes as they are read

Method Detail

### read

    public int read()
             throws java.io.IOException

  Reads a byte from the subsumed stream, updating the byte count and the checksums.

  Overrides:
    `read` in class `java.io.FilterInputStream`
  Throws:
    `java.io.IOException`

### read

    public int read(byte[] b)
             throws java.io.IOException

  Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. All bytes read are fed through the checksummer.

  Overrides:
    `read` in class `java.io.FilterInputStream`
  Throws:
    `java.io.IOException`

### read

    public int read(byte[] b,
                    int off,
                    int len)
             throws java.io.IOException

  Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer. All bytes read are fed through the checksummer.

  Overrides:
    `read` in class `java.io.FilterInputStream`
  Throws:
    `java.io.IOException`

### skip

    public long skip(long n)
              throws java.io.IOException

  Skips n bytes. Reads them and feeds them through the checksummer.

  Overrides:
    `skip` in class `java.io.FilterInputStream`
  Throws:
    `java.io.IOException`

### close

    public void close()
               throws java.io.IOException

  Closes the subsumed stream.

  Specified by:
    `close` in interface `java.io.Closeable`
  Overrides:
    `close` in class `java.io.FilterInputStream`
  Throws:
    `java.io.IOException`

### getNBytes

    public long getNBytes()

  Returns the byte count to date on the stream. This returns the number of bytes read. Because of buffering, this is not a reliable indicator of how many bytes have actually been processed.

### getChecksummer

    public Checksummer getChecksummer()

  Returns the Checksummer object.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD