Class RAFInputStream

java.lang.Object
java.io.InputStream
edu.harvard.hul.ois.jhove.RAFInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class RAFInputStream extends InputStream
An InputStream layered on top of a RandomAccessFile. This is useful for a Module which has requirements that force it to use a RandomAccessFile, but is usually accessed sequentially. An RAFInputStream maintains its own position information in the file, so multiple RAFInputStreams in the same file will work without interference. However, this class is not thread-safe.
Author:
Gary McGath
  • Constructor Details

    • RAFInputStream

      public RAFInputStream(RandomAccessFile raf)
      Constructor with default buffer size. The stream starts at the current position of the RandomAccessFile.
      Parameters:
      raf - the file on which the stream is to be based.
    • RAFInputStream

      public RAFInputStream(RandomAccessFile raf, int bufferSize)
      Constructor with buffer size. The stream starts at the current position of the RandomAccessFile.
      Parameters:
      raf - the file on which the stream is to be based.
      bufferSize - the buffer size to be used. If less than or equal to 0, the default buffer size is used.
  • Method Details

    • read

      public int read() throws IOException
      Reads a single byte from the file.
      Specified by:
      read in class InputStream
      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.
      Overrides:
      read in class InputStream
      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.
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • skip

      public long skip(long n) throws IOException
      Skips some number of bytes.
      Overrides:
      skip in class InputStream
      Returns:
      the number of bytes actually skipped.
      Throws:
      IOException
    • available

      public int available() throws IOException
      Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking. A single read or skip of this many bytes will not block, but may read or skip fewer bytes.
      Overrides:
      available in class InputStream
      Returns:
      an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, or 0 when it reaches the end of the input stream.
      Throws:
      IOException
    • getRAF

      public RandomAccessFile getRAF()
      Returns the RandomAccessFile object.
    • seek

      public void seek(long offset) throws IOException
      Positions the stream to a different point in the file, invalidating the buffer.
      Throws:
      IOException
    • getFilePos

      public long getFilePos() throws IOException
      Returns the current position in the file. What is reported is the position of the byte in the file which was last extracted from the buffer.
      Throws:
      IOException