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
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
ConstructorsConstructorDescriptionConstructor with default buffer size.RAFInputStream(RandomAccessFile raf, int bufferSize) Constructor with buffer size. -
Method Summary
Modifier and TypeMethodDescriptionintReturns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.longReturns the current position in the file.getRAF()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, skipNBytes, transferTo
-
Constructor Details
-
RAFInputStream
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
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
Reads a single byte from the file.- Specified by:
readin classInputStream- Throws:
IOException
-
read
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:
readin classInputStream- Throws:
IOException
-
read
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:
readin classInputStream- Throws:
IOException
-
skip
Skips some number of bytes.- Overrides:
skipin classInputStream- Returns:
- the number of bytes actually skipped.
- Throws:
IOException
-
available
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:
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
Returns the RandomAccessFile object. -
seek
Positions the stream to a different point in the file, invalidating the buffer.- Throws:
IOException
-
getFilePos
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
-