# Class SeekableByteChannelPrefetcher (0.133.0)

0.133.0 (latest) 0.131.0 0.128.13 0.127.38 0.126.19 0.125.0 0.124.21 0.123.28

    public final class SeekableByteChannelPrefetcher implements SeekableByteChannel

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).

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> SeekableByteChannelPrefetcher

## Implements

[SeekableByteChannel](https://docs.oracle.com/javase/8/docs/api/java/nio/channels/SeekableByteChannel.html)

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### addPrefetcher(int bufferSizeMB, SeekableByteChannel channel)

    public static SeekableByteChannel addPrefetcher(int bufferSizeMB, SeekableByteChannel channel)

Wraps the provided SeekableByteChannel within a SeekableByteChannelPrefetcher, using the
provided buffer size

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `bufferSizeMB` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` buffer size in MB |
| `channel` | `https://docs.oracle.com/javase/8/docs/api/java/nio/channels/SeekableByteChannel.html` channel to wrap in the prefetcher |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/nio/channels/SeekableByteChannel.html` | wrapped channel |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

## Methods

### close()

    public void 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.

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | If an I/O error occurs |

### fetch(long position)

    public ByteBuffer fetch(long position)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `position` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/InterruptedException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutionException.html` |   |

### getStatistics()

    public SeekableByteChannelPrefetcher.Statistics getStatistics()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-nio/latest/com.google.cloud.storage.contrib.nio.SeekableByteChannelPrefetcher.Statistics` |   |

### isOpen()

    public boolean isOpen()

Tells whether or not this channel is open.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if, and only if, this channel is open |

### position()

    public long position()

Returns this channel's position.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | This channel's position, a non-negative integer counting the number of bytes from the beginning of the entity to the current position |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | If this channel is closed |

### position(long newPosition)

    public SeekableByteChannel position(long newPosition)

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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `newPosition` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` The new position, a non-negative integer counting the number of bytes from the beginning of the entity |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/nio/channels/SeekableByteChannel.html` | This channel |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | If this channel is closed |

### read(ByteBuffer dst)

    public synchronized int read(ByteBuffer dst)

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.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `dst` | `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` buffer to write into |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### size()

    public long size()

Returns the current size of entity to which this channel is connected.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | The current size, measured in bytes |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | If this channel is closed |

### truncate(long size)

    public SeekableByteChannel truncate(long size)

Not supported.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `size` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/nio/channels/SeekableByteChannel.html` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### write(ByteBuffer src)

    public int write(ByteBuffer src)

Writing isn't supported.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `src` | `https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |