public class MappedFileChannelInputStream extends BufferInputStream
ChannelInputStream
that operates on a
file. The position is restored before every read operation, so it is safe
to use multiple instances of this class over the same file channel. However,
if multiple threads use the same instance of this class, the access to the
instance must be synchronized.Constructor and Description |
---|
MappedFileChannelInputStream(java.nio.channels.FileChannel fileChannel,
long position,
long maxLength)
Creates a new instance of FileChannelInputStream.
|
Modifier and Type | Method and Description |
---|---|
long |
getPosition()
Returns the current position in the file.
|
java.nio.ByteBuffer |
readInput(int minBytes)
Returns a buffer that contains at least
minBytes bytes. |
void |
reset()
Repositions this stream to the starting position.
|
void |
setPosition(long position)
Set the position from which the data will be read.
|
public MappedFileChannelInputStream(java.nio.channels.FileChannel fileChannel, long position, long maxLength) throws java.io.IOException
fileChannel
- the file channel from which to read dataposition
- the starting position of the filemaxLength
- the maximal length of datajava.io.IOException
- if there was an error using readChannelpublic void reset() throws java.io.IOException
reset
in class java.io.InputStream
java.io.IOException
public long getPosition()
getPosition
in class BufferInputStream
public void setPosition(long position) throws java.io.IOException
setPosition
in class BufferInputStream
position
- the new positionjava.io.IOException
- if the specified position is outside the boundariespublic java.nio.ByteBuffer readInput(int minBytes) throws java.io.IOException
BinaryInput
minBytes
bytes.
If the buffer with the required number of bytes cannot be provided, an
IOException
is thrown. Note that the returned
buffer can provide more than minBytes
.readInput
in interface BinaryInput
readInput
in class BufferInputStream
minBytes
- the minimal number of bytes that must be available for reading from the bufferjava.io.IOException
- if there was an error while preparing a buffer with minBytes
bytes