Package edu.harvard.hul.ois.jhove
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 Summary
Constructors Constructor Description RAFInputStream(RandomAccessFile raf)Constructor with default buffer size.RAFInputStream(RandomAccessFile raf, int bufferSize)Constructor with buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.longgetFilePos()Returns the current position in the file.RandomAccessFilegetRAF()Returns the RandomAccessFile object.intread()Reads a single byte from the file.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.voidseek(long offset)Positions the stream to a different point in the file, invalidating the buffer.longskip(long n)Skips some number of bytes.-
Methods inherited from class java.io.InputStream
close, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, transferTo
-
-
-
-
Constructor Detail
-
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 Detail
-
read
public int read() throws IOExceptionReads a single byte from the file.- Specified by:
readin classInputStream- 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.- Overrides:
readin classInputStream- 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.- Overrides:
readin classInputStream- Throws:
IOException
-
skip
public long skip(long n) throws IOExceptionSkips some number of bytes.- Overrides:
skipin classInputStream- Returns:
- the number of bytes actually skipped.
- Throws:
IOException
-
available
public int available() throws IOExceptionReturns 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:
availablein classInputStream- Returns:
- an estimate of the number of bytes that can be read (or skipped
over) from this input stream without blocking, or
0when 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 IOExceptionPositions the stream to a different point in the file, invalidating the buffer.- Throws:
IOException
-
getFilePos
public long getFilePos() throws IOExceptionReturns 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
-
-