public class DesugarSeekableByteChannel extends Object implements SeekableByteChannel
SeekableByteChannel for desugar support.| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes an open channel.
|
static DesugarSeekableByteChannel |
create(Path path,
Set<? extends OpenOption> openOptions) |
FileChannel |
getFileChannel() |
boolean |
isOpen()
Returns true if this channel is open.
|
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.
|
public static DesugarSeekableByteChannel create(Path path, Set<? extends OpenOption> openOptions) throws IOException
IOExceptionpublic FileChannel getFileChannel()
public int read(ByteBuffer dst) throws IOException
SeekableByteChannel 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.
read in interface ReadableByteChannelread in interface SeekableByteChanneldst - the byte buffer to receive the bytes.AsynchronousCloseException - if another thread closes the channel during the read.ClosedByInterruptException - if another thread interrupts the calling thread while the
operation is in progress. The interrupt state of the calling
thread is set and the channel is closed.ClosedChannelException - if the channel is closed.IOException - another I/O error occurs, details are in the message.public int write(ByteBuffer src) throws IOException
SeekableByteChannel Bytes are written starting at this channel's current position, unless
the channel is connected to an entity such as a file that is opened with
the APPEND option, in
which case the position is first advanced to the end. The entity to which
the channel is connected is grown, if necessary, to accommodate the
written bytes, and then the position is updated with the number of bytes
actually written. Otherwise this method behaves exactly as specified by
the WritableByteChannel interface.
write in interface SeekableByteChannelwrite in interface WritableByteChannelsrc - the byte buffer containing the bytes to be written.ClosedChannelException - if the channel was already closed.AsynchronousCloseException - if another thread closes the channel during the write.ClosedByInterruptException - if another thread interrupt the calling thread during the
write.IOException - another IO exception occurs, details are in the message.public long position()
throws IOException
SeekableByteChannelposition in interface SeekableByteChannelClosedChannelException - If this channel is closedIOException - If some other I/O error occurspublic SeekableByteChannel position(long newPosition) throws IOException
SeekableByteChannelSetting 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.
position in interface SeekableByteChannelnewPosition - The new position, a non-negative integer counting
the number of bytes from the beginning of the entityClosedChannelException - If this channel is closedIOException - If some other I/O error occurspublic long size()
throws IOException
SeekableByteChannelsize in interface SeekableByteChannelClosedChannelException - If this channel is closedIOException - If some other I/O error occurspublic SeekableByteChannel truncate(long size) throws IOException
SeekableByteChannelIf the given size is less than the current size then the entity is truncated, discarding any bytes beyond the new end. If the given size is greater than or equal to the current size then the entity is not modified. In either case, if the current position is greater than the given size then it is set to that size.
An implementation of this interface may prohibit truncation when
connected to an entity, typically a file, opened with the APPEND option.
truncate in interface SeekableByteChannelsize - The new size, a non-negative byte countClosedChannelException - If this channel is closedIOException - If some other I/O error occurspublic boolean isOpen()
Channelpublic void close()
throws IOException
Channel
If an attempt is made to perform an operation on a closed channel then a
ClosedChannelException will be thrown on that attempt.
If multiple threads attempt to simultaneously close a channel, then only one thread will run the closure code, and others will be blocked until the first returns.
close in interface Closeableclose in interface AutoCloseableclose in interface ChannelIOException - if a problem occurs closing the channel.