public class ByteBufferInputStream
extends java.io.InputStream
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.
| Modifier and Type | Field and Description |
|---|---|
static long |
CHUNK_SIZE
The size of a chunk created by
map(FileChannel, FileChannel.MapMode). |
| Modifier | Constructor and Description |
|---|---|
|
ByteBufferInputStream(java.nio.ByteBuffer byteBuffer)
Creates a new byte-buffer input stream from a single
ByteBuffer. |
protected |
ByteBufferInputStream(java.nio.ByteBuffer[] byteBuffer,
long size,
int curr,
boolean[] readyToUse)
Creates a new byte-buffer input stream.
|
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
ByteBufferInputStream |
copy() |
long |
length() |
static ByteBufferInputStream |
map(java.nio.channels.FileChannel fileChannel)
Creates a new read-only byte-buffer input stream by mapping a given file channel.
|
static ByteBufferInputStream |
map(java.nio.channels.FileChannel fileChannel,
java.nio.channels.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) |
public static final long CHUNK_SIZE
map(FileChannel, FileChannel.MapMode).public ByteBufferInputStream(java.nio.ByteBuffer byteBuffer)
ByteBuffer.byteBuffer - the underlying byte buffer.protected ByteBufferInputStream(java.nio.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.public static ByteBufferInputStream map(java.nio.channels.FileChannel fileChannel) throws java.io.IOException
fileChannel - the file channel that will be mapped.fileChannel.java.io.IOExceptionpublic static ByteBufferInputStream map(java.nio.channels.FileChannel fileChannel, java.nio.channels.FileChannel.MapMode mapMode) throws java.io.IOException
fileChannel - the file channel that will be mapped.mapMode - this must be FileChannel.MapMode.READ_ONLY.fileChannel.java.io.IOExceptionpublic int available()
available in class java.io.InputStreampublic boolean markSupported()
markSupported in class java.io.InputStreampublic void mark(int unused)
mark in class java.io.InputStreampublic void reset()
throws java.io.IOException
reset in class java.io.InputStreamjava.io.IOExceptionpublic long skip(long n)
throws java.io.IOException
skip in class java.io.InputStreamjava.io.IOExceptionpublic int read()
read in class java.io.InputStreampublic int read(byte[] b,
int offset,
int length)
read in class java.io.InputStreampublic long length()
public long position()
public void position(long newPosition)
public ByteBufferInputStream copy()
Copyright © 2019 The International Internet Preservation Consortium. All Rights Reserved.