InputStream implementation based on an underlying FileChannel's memory mapped ByteBuffer,
supporting mark and reset().
Implementation allows full memory mapped ByteBuffer coverage via FileChannel
beyond its size limitation of Integer#MAX_VALUE utilizing an array of ByteBuffer slices.
Implementation further allows full random access via position() and position(long)
and accessing the memory mapped ByteBuffer slices directly via currentSlice() and nextSlice().
| Modifier and Type | Class and Description |
|---|---|
| public static enum | |
| public static interface | MappedByteBufferInputStream.
File resize interface allowing a file to change its size,
e.g. via |
| Modifier and Type | Field and Description |
|---|---|
| private Method | |
| private boolean | |
| private MappedByteBufferInputStream. | |
| pack-priv static final boolean | |
| public static final int | DEFAULT_SLICE_SHIFT
Default slice shift, i.e. 1L << shift, denoting slice size in MiB:
|
| private final FileChannel | |
| private MappedByteBufferInputStream. | |
| private boolean | |
| private long | |
| private Method | |
| private final FileChannel. | |
| private static final MappedByteBufferInputStream. | |
| private int | |
| private int | |
| private int | |
| private ByteBuffer[] | |
| private WeakReference | |
| private int | |
| private int | |
| private final int | |
| private boolean | |
| private long |
| Access | Constructor and Description |
|---|---|
| pack-priv | MappedByteBufferInputStream(final FileChannel fc, final FileChannel.
|
| public | MappedByteBufferInputStream(final FileChannel
the file channel to be mapped lazily. fileChannel, final FileChannel.the map mode, default is mmode,FileChannel..the caching mode, default is cmode,CacheMode#FLUSH_PRE_HARD.the pow2 slice size, default is sliceShift)DEFAULT_SLICE_SHIFT.Creates a new instance using the given |
| public | MappedByteBufferInputStream(final FileChannel
the file channel to be used. fileChannel, final FileChannel.the map mode, default is mmode,FileChannel..the caching mode, default is cmodeCacheMode#FLUSH_PRE_HARD.Creates a new instance using the given |
| public | MappedByteBufferInputStream(final FileChannel
the file channel to be used. fileChannel)Creates a new instance using the given |
| Modifier and Type | Method and Description |
|---|---|
| public final synchronized int | |
| pack-priv final synchronized void | |
| private synchronized void | |
| private synchronized boolean | |
| private synchronized void | |
| public final synchronized void | close()
Overrides java. Implements java. |
| public final synchronized ByteBuffer | |
| pack-priv final void | |
| public final synchronized void | flush(final boolean
TODO metaData)Similar to |
| private final synchronized void | |
| private synchronized void | |
| public final synchronized MappedByteBufferInputStream. | |
| pack-priv final FileChannel. | |
| public final synchronized MappedByteBufferOutputStream | getOutputStream(final MappedByteBufferInputStream.
Returns a new MappedByteBufferOutputStream instance sharing all resources of this input stream, including all buffer slices. |
| public final synchronized boolean | |
| private synchronized void | |
| public final synchronized long | |
| public final synchronized void | mark(final int
the maximum limit of bytes that can be read before
the mark position becomes invalid. readlimit)Overrides java. |
| public final boolean | markSupported()
Overrides java. mark and
reset methods.
|
| public final synchronized ByteBuffer | nextSlice()
Return the next mapped |
| public final synchronized void | notifyLengthChange(final long
the new total size newTotalSize)Notify this instance that the underlying |
| private final synchronized void | |
| public final synchronized long | |
| public final synchronized MappedByteBufferInputStream | Returns: this instanceThe new position, which must be non-negative and ≤ newPosition)length().Sets the absolute position of the |
| private final synchronized void | |
| public final synchronized int | read()
Implements abstract java. |
| public final synchronized int | read(final byte[]
the buffer into which the data is read. b, final int the start offset in array off, final int b
at which the data is written.the maximum number of bytes to read. len)Overrides java. len bytes of data from the input stream into
an array of bytes.
|
| public final synchronized int | Returns: the number of bytes read, -1 for EOSthe b, final int ByteBuffer sink, data is written at current ByteBuffer#position()the number of bytes to read len)Perform similar to |
| public final synchronized long | remaining()
Returns the number of remaining available bytes of the |
| public final synchronized void | reset()
Overrides java. mark method was last called on this input stream.
|
| public final synchronized void | |
| public final synchronized void | setLength(final long
the new total size newTotalSize)Resize the underlying |
| public final synchronized void | |
| public final synchronized long | skip(final long
the number of bytes to be skipped. n)Overrides java. n bytes of data from this input
stream.
|
| pack-priv synchronized void | |
| pack-priv synchronized void |
| cClean | back to summary |
|---|---|
| private Method cClean | |
| cleanerInit | back to summary |
|---|---|
| private boolean cleanerInit | |
| cmode | back to summary |
|---|---|
| private MappedByteBufferInputStream. | |
| DEBUG | back to summary |
|---|---|
| pack-priv static final boolean DEBUG | |
| DEFAULT_SLICE_SHIFT | back to summary |
|---|---|
| public static final int DEFAULT_SLICE_SHIFT Default slice shift, i.e. 1L << shift, denoting slice size in MiB:
In case the default is too much of-used up address-space, one may choose other values:
| |
| fc | back to summary |
|---|---|
| private final FileChannel fc | |
| fileResizeOp | back to summary |
|---|---|
| private MappedByteBufferInputStream. | |
| hasCleaner | back to summary |
|---|---|
| private boolean hasCleaner | |
| mark | back to summary |
|---|---|
| private long mark | |
| mbbCleaner | back to summary |
|---|---|
| private Method mbbCleaner | |
| mmode | back to summary |
|---|---|
| private final FileChannel. | |
| NoFileResize | back to summary |
|---|---|
| private static final MappedByteBufferInputStream. | |
| refCount | back to summary |
|---|---|
| private int refCount | |
| sliceCount | back to summary |
|---|---|
| private int sliceCount | |
| sliceIdx | back to summary |
|---|---|
| private int sliceIdx | |
| slices | back to summary |
|---|---|
| private ByteBuffer[] slices | |
| slices2GC | back to summary |
|---|---|
| private WeakReference<ByteBuffer>[] slices2GC | |
| slices2GCEntries | back to summary |
|---|---|
| private int slices2GCEntries | |
| slicesEntries | back to summary |
|---|---|
| private int slicesEntries | |
| sliceShift | back to summary |
|---|---|
| private final int sliceShift | |
| synchronous | back to summary |
|---|---|
| private boolean synchronous | |
| totalSize | back to summary |
|---|---|
| private long totalSize | |
| MappedByteBufferInputStream | back to summary |
|---|---|
| pack-priv MappedByteBufferInputStream(final FileChannel fc, final FileChannel. | |
| MappedByteBufferInputStream | back to summary |
|---|---|
| public MappedByteBufferInputStream(final FileChannel fileChannel, final FileChannel. Creates a new instance using the given
The
| |
| MappedByteBufferInputStream | back to summary |
|---|---|
| public MappedByteBufferInputStream(final FileChannel fileChannel, final FileChannel. Creates a new instance using the given
The
| |
| MappedByteBufferInputStream | back to summary |
|---|---|
| public MappedByteBufferInputStream(final FileChannel fileChannel) throws IOException Creates a new instance using the given
The
| |
| available | back to summary |
|---|---|
| public final synchronized int available() throws IOException Overrides java. Doc from java. See Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected. The read might be on the same thread or another thread. A single read or skip of this many bytes will not block, but may read or skip fewer bytes. Note that while some implementations of A subclass's implementation of this method may choose to throw an
| |
| checkOpen | back to summary |
|---|---|
| pack-priv final synchronized void checkOpen() throws IOException | |
| cleanAllSlices | back to summary |
|---|---|
| private synchronized void cleanAllSlices(final boolean syncBuffers) throws IOException | |
| cleanBuffer | back to summary |
|---|---|
| private synchronized boolean cleanBuffer(final ByteBuffer mbb, final boolean syncBuffer) throws IOException | |
| cleanSlice | back to summary |
|---|---|
| private synchronized void cleanSlice(final int i, final boolean syncBuffer) throws IOException | |
| close | back to summary |
|---|---|
| public final synchronized void close() throws IOException Overrides java. Implements java. Doc from java. Closes this input stream and releases any system resources associated with the stream.
| |
| currentSlice | back to summary |
|---|---|
| public final synchronized ByteBuffer currentSlice() throws IOException Return the mapped
Due to the nature of using sliced buffers mapping the whole region,
user has to determine whether the returned buffer covers the desired region
and may fetch the
| |
| dbgDump | back to summary |
|---|---|
| pack-priv final void dbgDump(final String prefix, final PrintStream out) | |
| flush | back to summary |
|---|---|
| public final synchronized void flush(final boolean metaData) throws IOException Similar to
| |
| flushImpl | back to summary |
|---|---|
| private final synchronized void flushImpl(final boolean metaData, final boolean syncBuffer) throws IOException | |
| flushSlice | back to summary |
|---|---|
| private synchronized void flushSlice(final int i, final boolean syncBuffer) throws IOException | |
| getCacheMode | back to summary |
|---|---|
| public final synchronized MappedByteBufferInputStream. Return the used
If a desired | |
| getMapMode | back to summary |
|---|---|
| pack-priv final FileChannel. | |
| getOutputStream | back to summary |
|---|---|
| public final synchronized MappedByteBufferOutputStream getOutputStream(final MappedByteBufferInputStream. Returns a new MappedByteBufferOutputStream instance sharing all resources of this input stream, including all buffer slices.
| |
| getSynchronous | back to summary |
|---|---|
| public final synchronized boolean getSynchronous() Return | |
| initCleaner | back to summary |
|---|---|
| private synchronized void initCleaner(final ByteBuffer bb) | |
| length | back to summary |
|---|---|
| public final synchronized long length() Returns the total size in bytes of the
| |
| mark | back to summary |
|---|---|
| public final synchronized void mark(final int readlimit) Overrides java. Doc from java. Marks the current position in this input stream. A subsequent call to
the The The general contract of Marking a closed stream should not have any effect on the stream.
Parameter
| |
| markSupported | back to summary |
|---|---|
| public final boolean markSupported() Overrides java. Doc from java. Tests if this input stream supports the
| |
| nextSlice | back to summary |
|---|---|
| public final synchronized ByteBuffer nextSlice() throws IOException Return the next mapped
If no subsequent slice is available,
| |
| notifyLengthChange | back to summary |
|---|---|
| public final synchronized void notifyLengthChange(final long newTotalSize) throws IOException Notify this instance that the underlying Should be called by user API when aware of such event.
| |
| notifyLengthChangeImpl | back to summary |
|---|---|
| private final synchronized void notifyLengthChangeImpl(final long newTotalSize, final long currentPosition) throws IOException | |
| position | back to summary |
|---|---|
| public final synchronized long position() throws IOException Returns the absolute position of the
| |
| position | back to summary |
|---|---|
| public final synchronized MappedByteBufferInputStream position(final long newPosition) throws IOException Sets the absolute position of the
| |
| position2 | back to summary |
|---|---|
| private final synchronized void position2(final long newPosition) throws IOException | |
| read | back to summary |
|---|---|
| public final synchronized int read() throws IOException Implements abstract java. Doc from java. Reads the next byte of data from the input stream. The value byte is
returned as an
| |
| read | back to summary |
|---|---|
| public final synchronized int read(final byte[] b, final int off, final int len) throws IOException Overrides java. Doc from java. Reads up to This method blocks until input data is available, end of file is detected, or an exception is thrown. If The first byte read is stored into element In every case, elements
| |
| read | back to summary |
|---|---|
| public final synchronized int read(final ByteBuffer b, final int len) throws IOException Perform similar to
| |
| remaining | back to summary |
|---|---|
| public final synchronized long remaining() throws IOException Returns the number of remaining available bytes of the
In contrast to
| |
| reset | back to summary |
|---|---|
| public final synchronized void reset() throws IOException Overrides java. Doc from java. Repositions this stream to the position at the time the
The general contract of
| |
| setFileResizeOp | back to summary |
|---|---|
public final synchronized void setFileResizeOp(final MappedByteBufferInputStream.
| |
| setLength | back to summary |
|---|---|
| public final synchronized void setLength(final long newTotalSize) throws IOException Resize the underlying
User must have a
Implementation calls
| |
| setSynchronous | back to summary |
|---|---|
| public final synchronized void setSynchronous(final boolean s) Enable or disable synchronous mode.
If synchronous mode is enabled, mapped buffers will be
If synchronous mode is enabled,
| |
| skip | back to summary |
|---|---|
| public final synchronized long skip(final long n) throws IOException Overrides java. Doc from java. Skips over and discards
| |
| syncSlice | back to summary |
|---|---|
| pack-priv synchronized void syncSlice(final ByteBuffer s) throws IOException | |
| syncSlice | back to summary |
|---|---|
| pack-priv synchronized void syncSlice(final ByteBuffer s, final boolean syncBuffer) throws IOException | |
| Modifier and Type | Field and Description |
|---|---|
| public static final MappedByteBufferInputStream. | FLUSH_NONE
Keep all previous lazily cached buffer slices alive, useful for hopping readers,
i.e. random access via |
| public static final MappedByteBufferInputStream. | FLUSH_PRE_HARD
Hard flush the previous lazily cached buffer slice when caching the next buffer slice, useful for sequential forward readers. |
| public static final MappedByteBufferInputStream. | FLUSH_PRE_SOFT
Soft flush the previous lazily cached buffer slice when caching the next buffer slice,
useful for sequential forward readers, as well as for hopping readers like |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static MappedByteBufferInputStream. | |
| public static MappedByteBufferInputStream. |
| FLUSH_NONE | back to summary |
|---|---|
| public static final MappedByteBufferInputStream. Keep all previous lazily cached buffer slices alive, useful for hopping readers,
i.e. random access via
Note that without flushing, the platform may fail memory mapping
due to virtual address space exhaustion. | |
| FLUSH_PRE_HARD | back to summary |
|---|---|
| public static final MappedByteBufferInputStream. Hard flush the previous lazily cached buffer slice when caching the next buffer slice, useful for sequential forward readers.
Besides clearing the buffer slice reference,
implementation attempts to hard flush the mapped buffer
using a This is the default. | |
| FLUSH_PRE_SOFT | back to summary |
|---|---|
| public static final MappedByteBufferInputStream. Soft flush the previous lazily cached buffer slice when caching the next buffer slice,
useful for sequential forward readers, as well as for hopping readers like
Implementation clears the buffer slice reference
while preserving a | |
| CacheMode | back to summary |
|---|---|
| private CacheMode() | |
| valueOf | back to summary |
|---|---|
| public static MappedByteBufferInputStream. | |
| values | back to summary |
|---|---|
| public static MappedByteBufferInputStream. | |
RandomAccessFile#setLength(long).
| Modifier and Type | Method and Description |
|---|---|
| public void |
| setLength | back to summary |
|---|---|
public void setLength(final long newSize) throws IOException
| |