|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.InputStream
it.unimi.dsi.fastutil.io.MeasurableInputStream
it.unimi.dsi.io.ByteBufferInputStream
public class ByteBufferInputStream
A bridge between byte buffers and input streams.
Java's memory-mapping facilities have
the severe limitation of mapping at most Integer.MAX_VALUE bytes, as they
expose the content of a file using a MappedByteBuffer. This class can expose
a file of arbitrary length as a repositionable MeasurableInputStream
that is actually based on an array of MappedByteBuffers, each mapping
a chunk of CHUNK_SIZE bytes.
| Field Summary | |
|---|---|
static long |
CHUNK_SIZE
The size of a chunk created by map(FileChannel, FileChannel.MapMode). |
| Constructor Summary | |
|---|---|
|
ByteBufferInputStream(ByteBuffer byteBuffer)
Creates a new byte-buffer input stream from a single ByteBuffer. |
protected |
ByteBufferInputStream(ByteBuffer[] byteBuffer,
long size,
int curr,
boolean[] readyToUse)
Creates a new byte-buffer input stream. |
| Method Summary | |
|---|---|
int |
available()
|
ByteBufferInputStream |
copy()
|
long |
length()
|
static ByteBufferInputStream |
map(FileChannel fileChannel,
FileChannel.MapMode mapMode)
Creates a new byte-buffer input stream by mapping a given file channel. |
void |
mark(int unused)
|
boolean |
markSupported()
|
long |
position()
|
void |
position(long newPosition)
|
int |
read()
|
int |
read(byte[] b,
int offset,
int length)
|
void |
reset()
|
long |
skip(long n)
|
| Methods inherited from class java.io.InputStream |
|---|
close, read |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long CHUNK_SIZE
map(FileChannel, FileChannel.MapMode).
| Constructor Detail |
|---|
public ByteBufferInputStream(ByteBuffer byteBuffer)
ByteBuffer.
byteBuffer - the underlying byte buffer.
protected ByteBufferInputStream(ByteBuffer[] byteBuffer,
long size,
int curr,
boolean[] readyToUse)
byteBuffer - the underlying byte buffers.size - the sum of the capacities of the byte buffers.curr - the current buffer (reading will start at this buffer from its current position).readyToUse - an array parallel to byteBuffer specifying which buffers do not need to be
duplicated before being used (the process will happen lazily); the array
will be used internally by the newly created byte-buffer input stream.| Method Detail |
|---|
public static ByteBufferInputStream map(FileChannel fileChannel,
FileChannel.MapMode mapMode)
throws IOException
fileChannel - the file channel that will be mapped.mapMode - this must be FileChannel.MapMode.READ_ONLY.
fileChannel.
IOExceptionpublic int available()
available in class InputStreampublic boolean markSupported()
markSupported in class InputStreampublic void mark(int unused)
mark in class InputStream
public void reset()
throws IOException
reset in class InputStreamIOException
public long skip(long n)
throws IOException
skip in class InputStreamIOExceptionpublic int read()
read in class InputStream
public int read(byte[] b,
int offset,
int length)
read in class InputStreampublic long length()
length in interface MeasurableStreampublic long position()
position in interface MeasurableStreamposition in interface RepositionableStreampublic void position(long newPosition)
position in interface RepositionableStreampublic ByteBufferInputStream copy()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||