Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## edu.harvard.hul.ois.jhove
Class RAFInputStream

    java.lang.Object
      java.io.InputStream
          edu.harvard.hul.ois.jhove.RAFInputStream

All Implemented Interfaces:
  java.io.Closeable

    public class RAFInputStream

extends java.io.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 Summary
`RAFInputStream(java.io.RandomAccessFile raf)` Constructor with default buffer size.
`RAFInputStream(java.io.RandomAccessFile raf, int bufferSize)` Constructor with buffer size.

Method Summary
`long` | `getFilePos()` Returns the current position in the file.
`java.io.RandomAccessFile` | `getRAF()` Returns the RandomAccessFile object.
`int` | `read()` Reads a single byte from the file.
`int` | `read(byte[] b)` Reads some number of bytes from the input stream and stores them into the buffer array b.
`int` | `read(byte[] b, int off, int len)` Reads up to len bytes of data from the input stream into an array of bytes.
`void` | `seek(long offset)` Positions the stream to a different point in the file.
`long` | `skip(long n)` Skips some number of bytes.

Methods inherited from class java.io.InputStream
`available, close, mark, markSupported, reset`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### RAFInputStream

    public RAFInputStream(java.io.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(java.io.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 Detail

### read

    public int read()
             throws java.io.IOException

  Reads a single byte from the file.

  Specified by:
    `read` in class `java.io.InputStream`
  Throws:
    `java.io.IOException`

### read

    public int read(byte[] b)
             throws java.io.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 `java.io.InputStream`
  Throws:
    `java.io.IOException`

### read

    public int read(byte[] b,
                    int off,
                    int len)
             throws java.io.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 `java.io.InputStream`
  Throws:
    `java.io.IOException`

### skip

    public long skip(long n)
              throws java.io.IOException

  Skips some number of bytes.

  Overrides:
    `skip` in class `java.io.InputStream`
  Returns:
    The number of bytes actually skipped.
  Throws:
    `java.io.IOException`

### getRAF

    public java.io.RandomAccessFile getRAF()

  Returns the RandomAccessFile object.

### seek

    public void seek(long offset)
              throws java.io.IOException

  Positions the stream to a different point in the file. This invalidates the buffer.

  Throws:
    `java.io.IOException`

### getFilePos

    public long getFilePos()
                    throws java.io.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:
    `java.io.IOException`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD