public interface DataChannel extends ByteChannel, GatheringByteChannel, ScatteringByteChannel
| Modifier and Type | Interface and Description |
|---|---|
static class |
DataChannel.CloseAsyncStatus
The status of the close async method.
|
static class |
DataChannel.FlushStatus
The status of the flush method.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this channel, which should be a blocking channel.
|
DataChannel.CloseAsyncStatus |
closeAsync()
Closes this channel, which should be a non-blocking channel.
|
void |
closeForcefully()
Closes this channel forcefully.
|
void |
configureBlocking(boolean block)
Adjusts this channel's blocking mode.
|
DataChannel.FlushStatus |
flush()
Attempts to flush any pending writes to the underlying socket buffer.
|
SocketAddress |
getRemoteAddress()
Returns the remote address to which this channel's socket is connected.
|
SocketChannel |
getSocketChannel()
Accessor for the underlying SocketChannel.
|
boolean |
isBlocking()
Tells whether or not every I/O operation on this channel will block
until it completes.
|
boolean |
isConnected()
Checks whether the channel is connected.
|
boolean |
isSecure()
Checks whether the channel encrypted.
|
boolean |
isTrustCapable()
Checks whether the channel capable of determining peer trust.
|
boolean |
isTrusted()
Checks whether the channel peer is trusted.
|
long |
read(ByteBuffer[] dsts,
int offset,
int length)
Reads a sequence of bytes from this channel into a subsequence of the
given buffers.
|
Socket |
socket()
Retrieves a socket associated with this channel.
|
long |
write(ByteBuffer[] srcs,
int offset,
int length)
Writes a sequence of bytes to this channel from a subsequence of the
given buffers.
|
writewritereadreadboolean isConnected()
true if the channel is connectedSocket socket()
SocketAddress getRemoteAddress() throws IOException
IOExceptionvoid configureBlocking(boolean block)
throws IOException
IOExceptionboolean isBlocking()
boolean isSecure()
boolean isTrustCapable()
boolean isTrusted()
long read(ByteBuffer[] dsts, int offset, int length) throws IOException
The method throws ClosedChannelException after channel is
closed. The channel is closed if any of the close(), closeForcefully() or closeAsync() was called (regardless of
the return value or exception thrown). The method may throw AsynchronousCloseException when another thread is closing the channel
concurrently.
The method should not block any of the close methods.
read in interface ScatteringByteChannelIOExceptionlong write(ByteBuffer[] srcs, int offset, int length) throws IOException
The behavior w.r.t the flush() method:
The behavior w.r.t the channel-close methods:
ClosedChannelException after channel is
closed. The channel is closed if any of the close(), closeForcefully() or closeAsync() was called and exited
(regardless of the return value or exception thrown). The method may
throw AsynchronousCloseException when another thread is closing
the channel concurrently.write in interface GatheringByteChannelIOExceptionDataChannel.FlushStatus flush() throws IOException
Calling this method is not needed in cases where write(java.nio.ByteBuffer[], int, int)
itself will push the data to the transport. In such cases, the method is
equivalent to a no-op method and should return DataChannel.FlushStatus.DISABLED.
The method throws ClosedChannelException after channel is
closed. The channel is closed if any of the close(), closeForcefully() or closeAsync() was called (regardless of
the return value or exception thrown). The method may throw AsynchronousCloseException when another thread is closing the channel
concurrently.
IOExceptionvoid close()
throws IOException
It is considered a coding error to call this method if the channel is
configured as non-blocking: use closeAsync() or closeForcefully() instead. If called for a non-blocking channel, this
method closes the channel forcefully and throws IllegalStateException.
The method cleanly closes the channel, blocking if necessary. The
method should only be blocked for its own connection operations (i.e.,
not by concurrent read(java.nio.ByteBuffer[], int, int),write(java.nio.ByteBuffer[], int, int), flush() methods
or lock acquisitions, etc). The method throws IOException if the
connection is unresponsive and timed out.
If the method detects a concurrent read(java.nio.ByteBuffer[], int, int), write(java.nio.ByteBuffer[], int, int) or
flush() method being called, the method throws IOException.
Implementations of this method should flush written data before closing the channel.
If an error occurs, the method attempts to forcefully close the channel, before throwing the exception. Only the first encountered exception is thrown.
The channel is closed (i.e., isOpen returns false)
after this method returns, even if an exception is thrown. The read(java.nio.ByteBuffer[], int, int), write(java.nio.ByteBuffer[], int, int) and flush() methods will throw ClosedChannelException when the channel is closed. These methods may
throw AsynchronousCloseException if called concurrently with
this method.
close in interface AutoCloseableclose in interface Channelclose in interface CloseableIOException - if an error occursDataChannel.CloseAsyncStatus closeAsync() throws IOException
It is considered a coding error to call this method if the channel is
configured as blocking: use close() or closeForcefully()
instead. If called for a blocking channel, this method closes the
channel forcefully and throws IllegalStateException.
The method cleanly closes the channel in a non-blocking manner. The
channel is closed (i.e., isOpen returns false) once the
method is called (regardless of return value or exception thrown). The
caller, however, should keep calling this method until it returns true or throws exception. The channel is cleanly closed if the method
returns true or forcefully closed if the method throws
exception.
Implementations of this method should flush written data before closing the channel.
If the method detects a concurrent read(java.nio.ByteBuffer[], int, int), write(java.nio.ByteBuffer[], int, int) or
flush() method being called, the method throws IOException.
If an error occurs, the method attempts to forcefully close the channel, before throwing the exception. Only the first encountered exception is thrown.
The read(java.nio.ByteBuffer[], int, int), write(java.nio.ByteBuffer[], int, int) and flush() methods will
throw ClosedChannelException when the channel is closed. These
methods may throw AsynchronousCloseException if called
concurrently with this method.
true if the channel is cleanly closedIOException - if there is an errorvoid closeForcefully()
throws IOException
The method returns immediately, i.e., it should not be blocked by
concurrent read(java.nio.ByteBuffer[], int, int), write(java.nio.ByteBuffer[], int, int) or flush() methods, nor
should it be blocked by socket operations.
The method does not guarantee to flush written data before closing the channel, nor does it guarantee to do any procedure required for a clean close.
The channel is closed (i.e., isOpen returns false)
after this method returns. The read(java.nio.ByteBuffer[], int, int), write(java.nio.ByteBuffer[], int, int) and flush() methods will throw ClosedChannelException when the
channel is closed. These methods may throw AsynchronousCloseException if called concurrently with this method.
IOException - if an error occursSocketChannel getSocketChannel()
Copyright © 2024. All rights reserved.