Package edu.harvard.hul.ois.jhove
Class CountedInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
edu.harvard.hul.ois.jhove.CountedInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
A FilterInputStream which passes only a specified
number of bytes, then returns an EOF condition.
- Author:
- Gary McGath
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintread()Reads a single byte from the stream and decrements the count of remaining bytes.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, close, mark, markSupported, resetMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
CountedInputStream
- Parameters:
instrm- The InputStream being countedcount- The number of bytes to be allowed
-
-
Method Details
-
read
Reads a single byte from the stream and decrements the count of remaining bytes. If the count is exhausted, returns -1 to signify end of file.- 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. The number of bytes read will not exceed the number of bytes remaining in the count. The count is decremented by the number of bytes actually read.- 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. The number of bytes read will not exceed the number of bytes remaining in the count. The count is decremented by the number of bytes actually read.- Overrides:
readin classFilterInputStream- Throws:
IOException
-
skip
Skips n bytes. Decrements the count by the number of bytes actually skipped.- Overrides:
skipin classFilterInputStream- Throws:
IOException
-