it.unimi.dsi.io
Class ByteBufferInputStream
java.lang.Object
java.io.InputStream
it.unimi.dsi.fastutil.io.MeasurableInputStream
it.unimi.dsi.io.ByteBufferInputStream
- All Implemented Interfaces:
- RepositionableStream, Closeable
public class ByteBufferInputStream
- extends MeasurableInputStream
- implements RepositionableStream
A bridge between byte buffers and input streams.
The main usefulness of this class is that of making it possible creating input streams
that are really based on a MappedByteBuffer
.
In particular, the factory method map(FileChannel, FileChannel.MapMode)
will memory-map an entire file into an array of ByteBuffer
and expose the array as
a ByteBufferInputStream
. This makes it possible to access easily mapped files larger
than 2GiB.
- Since:
- 1.2
- Author:
- Sebastiano Vigna
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CHUNK_SIZE
public static final long CHUNK_SIZE
- The size of a chunk created by
map(FileChannel, FileChannel.MapMode)
.
ByteBufferInputStream
public ByteBufferInputStream(ByteBuffer byteBuffer)
- Creates a new byte-buffer input stream from a single
ByteBuffer
.
- Parameters:
byteBuffer
- the underlying byte buffer.
ByteBufferInputStream
protected ByteBufferInputStream(ByteBuffer[] byteBuffer)
- Creates a new byte-buffer input stream.
- Parameters:
byteBuffer
- the underlying byte buffers.
map
public static ByteBufferInputStream map(FileChannel fileChannel,
FileChannel.MapMode mapMode)
throws IOException
- Throws:
IOException
available
public int available()
- Overrides:
available
in class InputStream
markSupported
public boolean markSupported()
- Overrides:
markSupported
in class InputStream
mark
public void mark(int unused)
- Overrides:
mark
in class InputStream
reset
public void reset()
throws IOException
- Overrides:
reset
in class InputStream
- Throws:
IOException
skip
public long skip(long n)
throws IOException
- Overrides:
skip
in class InputStream
- Throws:
IOException
read
public int read()
- Specified by:
read
in class InputStream
read
public int read(byte[] b,
int offset,
int length)
- Overrides:
read
in class InputStream
length
public long length()
- Specified by:
length
in class MeasurableInputStream
position
public long position()
- Specified by:
position
in interface RepositionableStream
- Specified by:
position
in class MeasurableInputStream
position
public void position(long newPosition)
- Specified by:
position
in interface RepositionableStream
copy
public ByteBufferInputStream copy()