public final class SeekableByteChannelPrefetcher
extends java.lang.Object
implements java.nio.channels.SeekableByteChannel
Modifier and Type | Field and Description |
---|---|
long |
bytesRead |
long |
bytesReturned |
long |
msBetweenCallsToRead |
long |
msCopyingData |
long |
msWaitingForData |
long |
nbGoingBack |
long |
nbHit |
long |
nbMiss |
long |
nbNearHit |
long |
nbReadsPastEnd |
Constructor and Description |
---|
SeekableByteChannelPrefetcher(java.nio.channels.SeekableByteChannel chan,
int bufSize) |
Modifier and Type | Method and Description |
---|---|
static java.nio.channels.SeekableByteChannel |
addPrefetcher(int bufferSizeMB,
java.nio.channels.SeekableByteChannel channel)
Wraps the provided SeekableByteChannel within a SeekableByteChannelPrefetcher, using the provided buffer size
|
void |
close()
Closes this channel.
|
java.nio.ByteBuffer |
fetch(long position) |
java.lang.String |
getStatistics() |
boolean |
isOpen()
Tells whether or not this channel is open.
|
long |
position()
Returns this channel's position.
|
java.nio.channels.SeekableByteChannel |
position(long newPosition)
Sets this channel's position.
|
int |
read(java.nio.ByteBuffer dst)
Reads a sequence of bytes from this channel into the given buffer.
|
long |
size()
Returns the current size of entity to which this channel is connected.
|
java.nio.channels.SeekableByteChannel |
truncate(long size)
Not supported.
|
int |
write(java.nio.ByteBuffer src)
Writing isn't supported.
|
public long msWaitingForData
public long msCopyingData
public long bytesReturned
public long bytesRead
public long msBetweenCallsToRead
public long nbHit
public long nbNearHit
public long nbMiss
public long nbGoingBack
public long nbReadsPastEnd
public SeekableByteChannelPrefetcher(java.nio.channels.SeekableByteChannel chan, int bufSize) throws java.io.IOException
java.io.IOException
public static java.nio.channels.SeekableByteChannel addPrefetcher(int bufferSizeMB, java.nio.channels.SeekableByteChannel channel)
bufferSizeMB
- buffer size in MBchannel
- channel to wrap in the prefetcherpublic java.lang.String getStatistics()
public java.nio.ByteBuffer fetch(long position) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
Bytes are read starting at this channel's current position, and
then the position is updated with the number of bytes actually read.
Otherwise this method behaves exactly as specified in the ReadableByteChannel
interface.
read
in interface java.nio.channels.ReadableByteChannel
read
in interface java.nio.channels.SeekableByteChannel
dst
- buffer to write intojava.io.IOException
public int write(java.nio.ByteBuffer src) throws java.io.IOException
write
in interface java.nio.channels.SeekableByteChannel
write
in interface java.nio.channels.WritableByteChannel
java.io.IOException
public long position() throws java.io.IOException
position
in interface java.nio.channels.SeekableByteChannel
java.nio.channels.ClosedChannelException
- If this channel is closedjava.io.IOException
- If some other I/O error occurspublic java.nio.channels.SeekableByteChannel position(long newPosition) throws java.io.IOException
Setting the position to a value that is greater than the current size is legal but does not change the size of the entity. A later attempt to read bytes at such a position will immediately return an end-of-file indication. A later attempt to write bytes at such a position will cause the entity to grow to accommodate the new bytes; the values of any bytes between the previous end-of-file and the newly-written bytes are unspecified.
Setting the channel's position is not recommended when connected to
an entity, typically a file, that is opened with the APPEND
option. When opened for
append, the position is first advanced to the end before writing.
position
in interface java.nio.channels.SeekableByteChannel
newPosition
- The new position, a non-negative integer counting
the number of bytes from the beginning of the entityjava.nio.channels.ClosedChannelException
- If this channel is closedjava.lang.IllegalArgumentException
- If the new position is negativejava.io.IOException
- If some other I/O error occurspublic long size() throws java.io.IOException
size
in interface java.nio.channels.SeekableByteChannel
java.nio.channels.ClosedChannelException
- If this channel is closedjava.io.IOException
- If some other I/O error occurspublic java.nio.channels.SeekableByteChannel truncate(long size) throws java.io.IOException
truncate
in interface java.nio.channels.SeekableByteChannel
java.io.IOException
public boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public void close() throws java.io.IOException
After a channel is closed, any further attempt to invoke I/O
operations upon it will cause a ClosedChannelException
to be
thrown.
If this channel is already closed then invoking this method has no effect.
This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
java.io.IOException
- If an I/O error occurs