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
  • Constructor Details

    • CountedInputStream

      public CountedInputStream(InputStream instrm, int count)
      Parameters:
      instrm - The InputStream being counted
      count - The number of bytes to be allowed
  • Method Details

    • read

      public int read() throws IOException
      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:
      read in class FilterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] b) throws 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. 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:
      read in class FilterInputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws 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. 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:
      read in class FilterInputStream
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Skips n bytes. Decrements the count by the number of bytes actually skipped.
      Overrides:
      skip in class FilterInputStream
      Throws:
      IOException