public class SimpleDataChannel extends AbstractDataChannel
DataChannel.CloseAsyncStatus, DataChannel.FlushStatusconfiguredBlocking, socketChannel| Constructor and Description |
|---|
SimpleDataChannel(SocketChannel socketChannel)
Constructor for general use.
|
| 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.
|
DataChannel.FlushStatus |
flush()
Returns DISABLED, since this implementation does not do any flushing.
|
boolean |
isOpen() |
boolean |
isSecure()
Is the channel encrypted?
|
boolean |
isTrustCapable()
Is the channel peer trust capable?
|
boolean |
isTrusted()
Is the channel peer trusted?
|
int |
read(ByteBuffer dst) |
long |
read(ByteBuffer[] dsts) |
long |
read(ByteBuffer[] dsts,
int offset,
int length)
Reads a sequence of bytes from this channel into a subsequence of the
given buffers.
|
int |
write(ByteBuffer src) |
long |
write(ByteBuffer[] srcs) |
long |
write(ByteBuffer[] srcs,
int offset,
int length)
Writes a sequence of bytes to this channel from a subsequence of the
given buffers.
|
configureBlocking, ensureCloseAsyncForNonBlocking, ensureCloseForBlocking, getRemoteAddress, getSocketChannel, isBlocking, isConnected, socketpublic SimpleDataChannel(SocketChannel socketChannel)
socketChannel - A SocketChannel, which should be connected.public int read(ByteBuffer dst) throws IOException
IOExceptionpublic long read(ByteBuffer[] dsts) throws IOException
IOExceptionpublic long read(ByteBuffer[] dsts, int offset, int length) throws IOException
DataChannelThe method throws ClosedChannelException after channel is
closed. The channel is closed if any of the DataChannel.close(), DataChannel.closeForcefully() or DataChannel.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.
IOExceptionpublic void close()
throws IOException
DataChannelIt is considered a coding error to call this method if the channel is
configured as non-blocking: use DataChannel.closeAsync() or DataChannel.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 DataChannel.read(java.nio.ByteBuffer[], int, int),DataChannel.write(java.nio.ByteBuffer[], int, int), DataChannel.flush() methods
or lock acquisitions, etc). The method throws IOException if the
connection is unresponsive and timed out.
If the method detects a concurrent DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) or
DataChannel.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 DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) and DataChannel.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 occurspublic DataChannel.CloseAsyncStatus closeAsync() throws IOException
DataChannelIt is considered a coding error to call this method if the channel is
configured as blocking: use DataChannel.close() or DataChannel.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 DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) or
DataChannel.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 DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) and DataChannel.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 errorpublic void closeForcefully()
throws IOException
DataChannelThe method returns immediately, i.e., it should not be blocked by
concurrent DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) or DataChannel.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 DataChannel.read(java.nio.ByteBuffer[], int, int), DataChannel.write(java.nio.ByteBuffer[], int, int) and DataChannel.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 occurspublic boolean isOpen()
public int write(ByteBuffer src) throws IOException
IOExceptionpublic long write(ByteBuffer[] srcs) throws IOException
IOExceptionpublic long write(ByteBuffer[] srcs, int offset, int length) throws IOException
DataChannelThe behavior w.r.t the DataChannel.flush() method:
The behavior w.r.t the channel-close methods:
ClosedChannelException after channel is
closed. The channel is closed if any of the DataChannel.close(), DataChannel.closeForcefully() or DataChannel.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.IOExceptionpublic boolean isSecure()
public boolean isTrusted()
public boolean isTrustCapable()
public DataChannel.FlushStatus flush()
Copyright © 2024. All rights reserved.