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
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the subsumed stream.Returns the Checksummer object.longReturns 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, resetMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
ChecksumInputStream
Constructor.- Parameters:
stream- Stream to be filteredcksummer- Object to calculate checksum on the bytes as they are read
-
-
Method Details
-
read
Reads a byte from the subsumed stream, updating the byte count and the checksums.- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
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:
readin classFilterInputStream- Throws:
IOException
-
read
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:
readin classFilterInputStream- Throws:
IOException
-
skip
Skips n bytes. Reads them and feeds them through the checksummer.- Overrides:
skipin classFilterInputStream- Throws:
IOException
-
close
Closes 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
Returns the Checksummer object.
-