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
public class CountedInputStream extends FilterInputStream
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 Constructor Description CountedInputStream(InputStream instrm, int count)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intread()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, reset
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
CountedInputStream
public CountedInputStream(InputStream instrm, int count)
- Parameters:
instrm- The InputStream being countedcount- The number of bytes to be allowed
-
-
Method Detail
-
read
public int read() throws IOExceptionReads 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
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. 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
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. 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
public long skip(long n) throws IOExceptionSkips n bytes. Decrements the count by the number of bytes actually skipped.- Overrides:
skipin classFilterInputStream- Throws:
IOException
-
-