SeekableByteChannelPrefetcher wraps an existing SeekableByteChannel to add prefetching. The
prefetching is done on a different thread, so you can write simple code that repeatedly calls
read() to get data, processes it, and then calls read again -- and yet this simple code overlaps
computation and communication for you. (Of course this is only worthwhile if the underlying
SeekableByteChannel doesn't already implement prefetching).
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.
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.
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 java.nio.channels.ReadableByteChannel interface.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Class SeekableByteChannelPrefetcher (0.128.2)\n\nVersion latestkeyboard_arrow_down\n\n- [0.128.2 (latest)](/java/docs/reference/google-cloud-nio/latest/com.google.cloud.storage.contrib.nio.SeekableByteChannelPrefetcher)\n- [0.128.1](/java/docs/reference/google-cloud-nio/0.128.1/com.google.cloud.storage.contrib.nio.SeekableByteChannelPrefetcher)\n- [0.127.38](/java/docs/reference/google-cloud-nio/0.127.38/com.google.cloud.storage.contrib.nio.SeekableByteChannelPrefetcher)\n- [0.126.19](/java/docs/reference/google-cloud-nio/0.126.19/com.google.cloud.storage.contrib.nio.SeekableByteChannelPrefetcher)\n- [0.125.0](/java/docs/reference/google-cloud-nio/0.125.0/com.google.cloud.storage.contrib.nio.SeekableByteChannelPrefetcher)\n- [0.124.21](/java/docs/reference/google-cloud-nio/0.124.21/com.google.cloud.storage.contrib.nio.SeekableByteChannelPrefetcher)\n- [0.123.28](/java/docs/reference/google-cloud-nio/0.123.28/com.google.cloud.storage.contrib.nio.SeekableByteChannelPrefetcher) \n\n public final class SeekableByteChannelPrefetcher implements SeekableByteChannel\n\nSeekableByteChannelPrefetcher wraps an existing SeekableByteChannel to add prefetching. The\nprefetching is done on a different thread, so you can write simple code that repeatedly calls\nread() to get data, processes it, and then calls read again -- and yet this simple code overlaps\ncomputation and communication for you. (Of course this is only worthwhile if the underlying\nSeekableByteChannel doesn't already implement prefetching). \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e SeekableByteChannelPrefetcher \n\nImplements\n----------\n\n[SeekableByteChannel](https://docs.oracle.com/javase/8/docs/api/java/nio/channels/SeekableByteChannel.html) \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### addPrefetcher(int bufferSizeMB, SeekableByteChannel channel)\n\n public static SeekableByteChannel addPrefetcher(int bufferSizeMB, SeekableByteChannel channel)\n\nWraps the provided SeekableByteChannel within a SeekableByteChannelPrefetcher, using the\nprovided buffer size\n\nMethods\n-------\n\n### close()\n\n public void close()\n\nCloses this channel.\n\n\nAfter a channel is closed, any further attempt to invoke I/O operations upon it will cause a\nClosedChannelException to be thrown.\n\n\nIf this channel is already closed then invoking this method has no effect.\n\n\nThis method may be invoked at any time. If some other thread has already invoked it,\nhowever, then another invocation will block until the first invocation is complete, after which\nit will return without effect.\n\n### fetch(long position)\n\n public ByteBuffer fetch(long position)\n\n### getStatistics()\n\n public SeekableByteChannelPrefetcher.Statistics getStatistics()\n\n### isOpen()\n\n public boolean isOpen()\n\nTells whether or not this channel is open.\n\n### position()\n\n public long position()\n\nReturns this channel's position.\n\n### position(long newPosition)\n\n public SeekableByteChannel position(long newPosition)\n\nSets this channel's position.\n\n\nSetting the position to a value that is greater than the current size is legal but does not\nchange the size of the entity. A later attempt to read bytes at such a position will\nimmediately return an end-of-file indication. A later attempt to write bytes at such a position\nwill cause the entity to grow to accommodate the new bytes; the values of any bytes between the\nprevious end-of-file and the newly-written bytes are unspecified.\n\nSetting the channel's position is not recommended when connected to an entity, typically a\nfile, that is opened with the APPEND option.\nWhen opened for append, the position is first advanced to the end before writing.\n\n### read(ByteBuffer dst)\n\n public synchronized int read(ByteBuffer dst)\n\nReads a sequence of bytes from this channel into the given buffer.\n\nBytes are read starting at this channel's current position, and then the position is updated\nwith the number of bytes actually read. Otherwise this method behaves exactly as specified in\nthe java.nio.channels.ReadableByteChannel interface.\n\n### size()\n\n public long size()\n\nReturns the current size of entity to which this channel is connected.\n\n### truncate(long size)\n\n public SeekableByteChannel truncate(long size)\n\nNot supported.\n\n### write(ByteBuffer src)\n\n public int write(ByteBuffer src)\n\nWriting isn't supported."]]