public abstract class AbstractSeekableByteChannel extends Object implements SeekableByteChannel
SeekableByteChannel implementations.
This class makes close() idempotent and provides utilities for
managing the channel's position. All I/O operations are left to subclasses.
| Modifier and Type | Field and Description |
|---|---|
protected long |
position
This channel's position.
|
| Constructor and Description |
|---|
AbstractSeekableByteChannel() |
| Modifier and Type | Method and Description |
|---|---|
protected int |
advancePosition(int numBytes)
Advances this channel's position by the given number of bytes, if it is
positive.
|
protected void |
checkIsOpen()
Checks that this channel is open.
|
void |
close() |
protected abstract void |
doClose()
Performs implementation-specific close actions.
|
boolean |
isOpen() |
long |
position() |
SeekableByteChannel |
position(long newPosition) |
protected boolean |
truncatePosition(long size)
Sets this channel's position to
size if it is less than the
current position. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitread, size, truncate, writeprotected long position
advancePosition(int) and
truncatePosition(long) when possible. This is exposed primarily
for efficiency when reading the position or setting it to an exact value.public final void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface ChannelIOExceptionprotected abstract void doClose()
throws IOException
IOException - if an I/O error occurs while closing this channel.public long position()
throws IOException
position in interface SeekableByteChannelIOExceptionpublic SeekableByteChannel position(long newPosition) throws IOException
position in interface SeekableByteChannelIOExceptionprotected final int advancePosition(int numBytes)
numBytes - the number of bytes transferredprotected final boolean truncatePosition(long size)
size if it is less than the
current position.size - the new size of the underlying resourcetrue if this channel's position changed, false
otherwiseprotected final void checkIsOpen()
throws ClosedChannelException
ClosedChannelException - if this channel is closed