Class SeekableByteChannelPrefetcher
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteChannel
,Channel
,ReadableByteChannel
,SeekableByteChannel
,WritableByteChannel
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic SeekableByteChannel
addPrefetcher
(int bufferSizeMB, SeekableByteChannel channel) Wraps the provided SeekableByteChannel within a SeekableByteChannelPrefetcher, using the provided buffer sizevoid
close()
Closes this channel.fetch
(long position) boolean
isOpen()
Tells whether or not this channel is open.long
position()
Returns this channel's position.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.truncate
(long size) Not supported.int
write
(ByteBuffer src) Writing isn't supported.
-
Method Details
-
addPrefetcher
public static SeekableByteChannel addPrefetcher(int bufferSizeMB, SeekableByteChannel channel) throws IOException Wraps the provided SeekableByteChannel within a SeekableByteChannelPrefetcher, using the provided buffer size- Parameters:
bufferSizeMB
- buffer size in MBchannel
- channel to wrap in the prefetcher- Returns:
- wrapped channel
- Throws:
IOException
-
getStatistics
-
fetch
-
read
Reads a sequence of bytes from this channel into the given buffer.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.- Specified by:
read
in interfaceReadableByteChannel
- Specified by:
read
in interfaceSeekableByteChannel
- Parameters:
dst
- buffer to write into- Throws:
IOException
-
write
Writing isn't supported.- Specified by:
write
in interfaceSeekableByteChannel
- Specified by:
write
in interfaceWritableByteChannel
- Throws:
IOException
-
position
Returns this channel's position.- Specified by:
position
in interfaceSeekableByteChannel
- Returns:
- This channel's position, a non-negative integer counting the number of bytes from the beginning of the entity to the current position
- Throws:
ClosedChannelException
- If this channel is closedIOException
- If some other I/O error occurs
-
position
Sets this channel's position.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.- Specified by:
position
in interfaceSeekableByteChannel
- Parameters:
newPosition
- The new position, a non-negative integer counting the number of bytes from the beginning of the entity- Returns:
- This channel
- Throws:
ClosedChannelException
- If this channel is closedIllegalArgumentException
- If the new position is negativeIOException
- If some other I/O error occurs
-
size
Returns the current size of entity to which this channel is connected.- Specified by:
size
in interfaceSeekableByteChannel
- Returns:
- The current size, measured in bytes
- Throws:
ClosedChannelException
- If this channel is closedIOException
- If some other I/O error occurs
-
truncate
Not supported.- Specified by:
truncate
in interfaceSeekableByteChannel
- Throws:
IOException
-
isOpen
public boolean isOpen()Tells whether or not this channel is open. -
close
Closes this channel.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.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If an I/O error occurs
-