Package 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:
Closeable,AutoCloseable
public class ChecksumInputStream extends 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
Constructors Constructor Description ChecksumInputStream(InputStream stream, Checksummer cksummer)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the subsumed stream.ChecksummergetChecksummer()Returns the Checksummer object.longgetNBytes()Returns the byte count to date on the stream.intread()Reads a byte from the subsumed stream, updating the byte count and the checksums.intread(byte[] b)Reads some number of bytes from the input stream and stores them into the buffer array b.intread(byte[] b, int off, int len)Reads up to len bytes of data from the input stream into an array of bytes.longskip(long n)Skips n bytes.-
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, reset
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
ChecksumInputStream
public ChecksumInputStream(InputStream stream, Checksummer cksummer)
Constructor.- Parameters:
stream- Stream to be filteredcksummer- Object to calculate checksum on the bytes as they are read
-
-
Method Detail
-
read
public int read() throws IOExceptionReads a byte from the subsumed stream, updating the byte count and the checksums.- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
public int read(byte[] b) throws IOExceptionReads 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:
readin classFilterInputStream- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOExceptionReads 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:
readin classFilterInputStream- Throws:
IOException
-
skip
public long skip(long n) throws IOExceptionSkips n bytes. Reads them and feeds them through the checksummer.- Overrides:
skipin classFilterInputStream- Throws:
IOException
-
close
public void close() throws IOExceptionCloses the subsumed stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterInputStream- Throws:
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.
-
-