public final class SeekableByteChannelPrefetcher extends Object implements SeekableByteChannel
Modifier and Type | Class and Description |
---|---|
static class |
SeekableByteChannelPrefetcher.Statistics |
Modifier and Type | Method and Description |
---|---|
static SeekableByteChannel |
addPrefetcher(int bufferSizeMB,
SeekableByteChannel channel)
Wraps the provided SeekableByteChannel within a SeekableByteChannelPrefetcher, using the
provided buffer size
|
void |
close()
Closes this channel.
|
ByteBuffer |
fetch(long position) |
SeekableByteChannelPrefetcher.Statistics |
getStatistics() |
boolean |
isOpen()
Tells whether or not this channel is open.
|
long |
position()
Returns this channel's position.
|
SeekableByteChannel |
position(long newPosition)
Sets this channel's position.
|
int |
read(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.
|
SeekableByteChannel |
truncate(long size)
Not supported.
|
int |
write(ByteBuffer src)
Writing isn't supported.
|
public static SeekableByteChannel addPrefetcher(int bufferSizeMB, SeekableByteChannel channel) throws IOException
bufferSizeMB
- buffer size in MBchannel
- channel to wrap in the prefetcherIOException
public SeekableByteChannelPrefetcher.Statistics getStatistics()
public ByteBuffer fetch(long position) throws InterruptedException, ExecutionException
public int read(ByteBuffer dst) throws 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 ReadableByteChannel
read
in interface SeekableByteChannel
dst
- buffer to write intoIOException
public int write(ByteBuffer src) throws IOException
write
in interface SeekableByteChannel
write
in interface WritableByteChannel
IOException
public long position() throws IOException
position
in interface SeekableByteChannel
ClosedChannelException
- If this channel is closedIOException
- If some other I/O error occurspublic SeekableByteChannel position(long newPosition) throws 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 SeekableByteChannel
newPosition
- The new position, a non-negative integer counting the number of bytes from
the beginning of the entityClosedChannelException
- If this channel is closedIllegalArgumentException
- If the new position is negativeIOException
- If some other I/O error occurspublic long size() throws IOException
size
in interface SeekableByteChannel
ClosedChannelException
- If this channel is closedIOException
- If some other I/O error occurspublic SeekableByteChannel truncate(long size) throws IOException
truncate
in interface SeekableByteChannel
IOException
public boolean isOpen()
public void close() throws 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 Closeable
close
in interface AutoCloseable
close
in interface Channel
IOException
- If an I/O error occursCopyright © 2019 Google LLC. All rights reserved.