SeekableByteChannel (Java SE 15 & JDK 15) (original) (raw)

All Superinterfaces:

[AutoCloseable](../../lang/AutoCloseable.html "interface in java.lang"), [ByteChannel](ByteChannel.html "interface in java.nio.channels"), [Channel](Channel.html "interface in java.nio.channels"), [Closeable](../../io/Closeable.html "interface in java.io"), [ReadableByteChannel](ReadableByteChannel.html "interface in java.nio.channels"), [WritableByteChannel](WritableByteChannel.html "interface in java.nio.channels")

All Known Implementing Classes:

[FileChannel](FileChannel.html "class in java.nio.channels")


public interface SeekableByteChannel extends ByteChannel

A byte channel that maintains a current position and allows the position to be changed.

A seekable byte channel is connected to an entity, typically a file, that contains a variable-length sequence of bytes that can be read and written. The current position can be queried andmodified. The channel also provides access to the current size of the entity to which the channel is connected. The size increases when bytes are written beyond its current size; the size decreases when it is truncated.

The position and truncate methods which do not otherwise have a value to return are specified to return the channel upon which they are invoked. This allows method invocations to be chained. Implementations of this interface should specialize the return type so that method invocations on the implementation class can be chained.

Since:

1.7

See Also:

Files.newByteChannel(java.nio.file.Path, java.util.Set, java.nio.file.attribute.FileAttribute...)

Modifier and Type Method Description
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) Truncates the entity, to which this channel is connected, to the given size.
int write​(ByteBuffer src) Writes a sequence of bytes to this channel from the given buffer.