public abstract class FiberSocketChannel
extends java.lang.Object
implements java.nio.channels.ByteChannel, java.nio.channels.ScatteringByteChannel, java.nio.channels.GatheringByteChannel, java.nio.channels.NetworkChannel
SocketChannel.| Constructor and Description |
|---|
FiberSocketChannel() |
| Modifier and Type | Method and Description |
|---|---|
abstract FiberSocketChannel |
bind(java.net.SocketAddress local) |
abstract void |
close() |
abstract void |
connect(java.net.SocketAddress remote)
Connects this channel.
|
abstract void |
connect(java.net.SocketAddress remote,
long timeout,
java.util.concurrent.TimeUnit timeUnit)
Connects this channel.
|
abstract java.net.SocketAddress |
getLocalAddress() |
abstract <T> T |
getOption(java.net.SocketOption<T> name) |
abstract java.net.SocketAddress |
getRemoteAddress()
Returns the remote address to which this channel's socket is connected.
|
abstract boolean |
isOpen() |
static FiberSocketChannel |
open()
Opens a socket channel.
|
static FiberSocketChannel |
open(ChannelGroup group)
Opens a socket channel.
|
static FiberSocketChannel |
open(ChannelGroup group,
java.net.SocketAddress remote)
Opens a socket channel and connects it to a remote address.
|
static FiberSocketChannel |
open(java.net.SocketAddress remote)
Opens a socket channel and connects it to a remote address.
|
abstract java.lang.Object |
provider()
Returns the IO provider that created this channel.
|
abstract int |
read(java.nio.ByteBuffer dst) |
abstract long |
read(java.nio.ByteBuffer[] dsts) |
abstract long |
read(java.nio.ByteBuffer[] dsts,
int offset,
int length) |
abstract long |
read(java.nio.ByteBuffer[] dsts,
int offset,
int length,
long timeout,
java.util.concurrent.TimeUnit unit)
Reads a sequence of bytes from this channel into a subsequence of the
given buffers.
|
abstract int |
read(java.nio.ByteBuffer dst,
long timeout,
java.util.concurrent.TimeUnit unit)
Reads a sequence of bytes from this channel into the given buffer.
|
abstract <T> FiberSocketChannel |
setOption(java.net.SocketOption<T> name,
T value) |
abstract FiberSocketChannel |
shutdownInput()
Shutdown the connection for reading without closing the channel.
|
abstract FiberSocketChannel |
shutdownOutput()
Shutdown the connection for writing without closing the channel.
|
abstract java.util.Set<java.net.SocketOption<?>> |
supportedOptions() |
abstract int |
write(java.nio.ByteBuffer src) |
abstract long |
write(java.nio.ByteBuffer[] srcs) |
abstract long |
write(java.nio.ByteBuffer[] srcs,
int offset,
int length) |
abstract long |
write(java.nio.ByteBuffer[] srcs,
int offset,
int length,
long timeout,
java.util.concurrent.TimeUnit unit)
Writes a sequence of bytes to this channel from a subsequence of the given
buffers.
|
abstract int |
write(java.nio.ByteBuffer src,
long timeout,
java.util.concurrent.TimeUnit unit)
Writes a sequence of bytes to this channel from the given buffer.
|
public static FiberSocketChannel open(ChannelGroup group) throws java.io.IOException, SuspendExecution
If the group parameter is null then the resulting channel is bound to the default group.
group - The group to which the newly constructed channel should be bound, or null for the default groupShutdownChannelGroupException - If the channel group is shutdownjava.io.IOException - If an I/O error occursSuspendExecutionpublic static FiberSocketChannel open() throws java.io.IOException, SuspendExecution
open((AsynchronousChannelGroup) null).java.io.IOException - If an I/O error occursSuspendExecutionpublic static FiberSocketChannel open(java.net.SocketAddress remote) throws java.io.IOException, SuspendExecution
This convenience method works as if by invoking the open()
method, invoking the connect method upon
the resulting socket channel, passing it remote, and then
returning that channel.
remote - The remote address to which the new channel is to be connectedAsynchronousCloseException - If another thread closes this channel
while the connect operation is in progressClosedByInterruptException - If another thread interrupts the current thread
while the connect operation is in progress, thereby
closing the channel and setting the current thread's
interrupt statusUnresolvedAddressException - If the given remote address is not fully resolvedUnsupportedAddressTypeException - If the type of the given remote address is not supportedjava.lang.SecurityException - If a security manager has been installed
and it does not permit access to the given remote endpointjava.io.IOException - If some other I/O error occursSuspendExecutionpublic static FiberSocketChannel open(ChannelGroup group, java.net.SocketAddress remote) throws java.io.IOException, SuspendExecution
This convenience method works as if by invoking the open()
method, invoking the connect method upon
the resulting socket channel, passing it remote, and then
returning that channel.
group - The group to which the newly constructed channel should be bound, or null for the default groupremote - The remote address to which the new channel is to be connectedAsynchronousCloseException - If another thread closes this channel
while the connect operation is in progressClosedByInterruptException - If another thread interrupts the current thread
while the connect operation is in progress, thereby
closing the channel and setting the current thread's
interrupt statusUnresolvedAddressException - If the given remote address is not fully resolvedUnsupportedAddressTypeException - If the type of the given remote address is not supportedjava.lang.SecurityException - If a security manager has been installed
and it does not permit access to the given remote endpointjava.io.IOException - If some other I/O error occursSuspendExecutionpublic abstract void connect(java.net.SocketAddress remote)
throws java.io.IOException,
SuspendExecution
This method initiates an operation to connect this channel. it blocks until the connection is successfully established or connection cannot be established. If the connection cannot be established then the channel is closed.
This method performs exactly the same security checks as the Socket class. That is, if a security manager has been
installed then this method verifies that its checkConnect method permits
connecting to the address and port number of the given remote endpoint.
remote - The remote address to which this channel is to be connectedUnresolvedAddressException - If the given remote address is not fully resolvedUnsupportedAddressTypeException - If the type of the given remote address is not supportedAlreadyConnectedException - If this channel is already connectedConnectionPendingException - If a connection operation is already in progress on this channelShutdownChannelGroupException - If the channel group has terminatedjava.lang.SecurityException - If a security manager has been installed and it does not permit access to the given remote endpointjava.io.IOExceptionSuspendExecutiongetRemoteAddress()public abstract void connect(java.net.SocketAddress remote,
long timeout,
java.util.concurrent.TimeUnit timeUnit)
throws java.io.IOException,
SuspendExecution,
java.util.concurrent.TimeoutException
This method initiates an operation to connect this channel. it blocks
until the connection is successfully established or connection cannot be
established or a timeout occurs while attempting to establish it. If the
connection cannot be established then the channel is closed but not so if
a timeout occurs (see http://stackoverflow.com/questions/20752756/how-to-set-java-nio-asynchronoussocketchannel-connect-timeout).
This method performs exactly the same security checks as the Socket class. That is, if a security manager has been
installed then this method verifies that its checkConnect method permits
connecting to the address and port number of the given remote endpoint.
remote - The remote address to which this channel is to be connectedtimeout - The timeout for the connection attempttimeUnit - The time unit for the connection attempt timeoutUnresolvedAddressException - If the given remote address is not fully resolvedUnsupportedAddressTypeException - If the type of the given remote address is not supportedAlreadyConnectedException - If this channel is already connectedConnectionPendingException - If a connection operation is already in progress on this channelShutdownChannelGroupException - If the channel group has terminatedjava.lang.SecurityException - If a security manager has been installed and it does not permit access to the given remote endpointjava.io.IOExceptionSuspendExecutionjava.util.concurrent.TimeoutExceptiongetRemoteAddress()public abstract long read(java.nio.ByteBuffer[] dsts,
int offset,
int length,
long timeout,
java.util.concurrent.TimeUnit unit)
throws java.io.IOException,
SuspendExecution
-1 if no bytes could be read because the channel has reached
end-of-stream.
This method initiates a read of up to r bytes from this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,
dsts[offset].remaining()
+ dsts[offset+1].remaining()
+ ... + dsts[offset+length-1].remaining()
at the moment that the read is attempted.
Suppose that a byte sequence of length n is read, where 0 < n <= r. Up to the first dsts[offset].remaining() bytes of this sequence are transferred into buffer dsts[offset], up to the next dsts[offset+1].remaining() bytes are transferred into buffer dsts[offset+1], and so forth, until the entire byte sequence is transferred into the given buffers. As many bytes as possible are transferred into each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit. The underlying operating system may impose a limit on the number of buffers that may be used in an I/O operation. Where the number of buffers (with bytes remaining), exceeds this limit, then the I/O operation is performed with the maximum number of buffers allowed by the operating system.
If a timeout is specified and the timeout elapses before the operation
completes then the method throws exception InterruptedByTimeoutException. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been read, or will not
be read from the channel into the given buffers, then further attempts to
read from the channel will cause an unspecific runtime exception to be
thrown.
dsts - The buffers into which bytes are to be transferredoffset - The offset within the buffer array of the first buffer into which
bytes are to be transferred; must be non-negative and no larger than
dsts.lengthlength - The maximum number of buffers to be accessed; must be non-negative
and no larger than dsts.length - offsettimeout - The maximum time for the I/O operation to completeunit - The time unit of the timeout argument-1 if no bytes could be read because the channel has reached end-of-stream.java.lang.IndexOutOfBoundsException - If the pre-conditions for the offset and length parameter aren't metjava.lang.IllegalArgumentException - If the buffer is read-onlyReadPendingException - If a read operation is already in progress on this channelNotYetConnectedException - If this channel is not yet connectedShutdownChannelGroupException - If the channel group has terminatedjava.nio.channels.InterruptedByTimeoutException - If a timeout is specified and the timeout elapses before the operation completesjava.io.IOExceptionSuspendExecutionpublic abstract int read(java.nio.ByteBuffer dst,
long timeout,
java.util.concurrent.TimeUnit unit)
throws java.io.IOException,
SuspendExecution
This method reads a sequence of bytes from this channel into the given buffer.
The returned result is the number of bytes read or
-1 if no bytes could be read because the channel has reached
end-of-stream.
If a timeout is specified and the timeout elapses before the method throws InterruptedByTimeoutException. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been read, or will not
be read from the channel into the given buffer, then further attempts to
read from the channel will cause an unspecific runtime exception to be
thrown.
Otherwise this method works in the same manner as the read(ByteBuffer).
method.
dst - The buffer into which bytes are to be transferredtimeout - The maximum time for the I/O operation to completeunit - The time unit of the timeout argument-1 if no bytes could be read because the channel has reached end-of-stream.java.lang.IllegalArgumentException - If the buffer is read-onlyReadPendingException - If a read operation is already in progress on this channelNotYetConnectedException - If this channel is not yet connectedShutdownChannelGroupException - If the channel group has terminatedjava.nio.channels.InterruptedByTimeoutException - If a timeout is specified and the timeout elapses before the operation completesjava.io.IOExceptionSuspendExecutionpublic abstract long write(java.nio.ByteBuffer[] srcs,
int offset,
int length,
long timeout,
java.util.concurrent.TimeUnit unit)
throws java.io.IOException,
SuspendExecution
This method writes of up to r bytes to this channel, where r is the total number of bytes remaining in the specified subsequence of the given buffer array, that is,
srcs[offset].remaining()
+ srcs[offset+1].remaining()
+ ... + srcs[offset+length-1].remaining()
at the moment that the write is attempted.
Suppose that a byte sequence of length n is written, where 0 < n <= r. Up to the first srcs[offset].remaining() bytes of this sequence are written from buffer srcs[offset], up to the next srcs[offset+1].remaining() bytes are written from buffer srcs[offset+1], and so forth, until the entire byte sequence is written. As many bytes as possible are written from each buffer, hence the final position of each updated buffer, except the last updated buffer, is guaranteed to be equal to that buffer's limit. The underlying operating system may impose a limit on the number of buffers that may be used in an I/O operation. Where the number of buffers (with bytes remaining), exceeds this limit, then the I/O operation is performed with the maximum number of buffers allowed by the operating system.
If a timeout is specified and the timeout elapses before the operation
completes then the method throws the exception InterruptedByTimeoutException. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been written, or will
not be written to the channel from the given buffers, then further attempts
to write to the channel will cause an unspecific runtime exception to be
thrown.
srcs - The buffers from which bytes are to be retrievedoffset - The offset within the buffer array of the first buffer from which
bytes are to be retrieved; must be non-negative and no larger than srcs.lengthlength - The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offsettimeout - The maximum time for the I/O operation to completeunit - The time unit of the timeout argumentjava.lang.IndexOutOfBoundsException - If the pre-conditions for the offset and length parameter aren't metWritePendingException - If a write operation is already in progress on this channelNotYetConnectedException - If this channel is not yet connectedShutdownChannelGroupException - If the channel group has terminatedjava.nio.channels.InterruptedByTimeoutException - If a timeout is specified and the timeout elapses before the operation completesjava.io.IOExceptionSuspendExecutionpublic abstract int write(java.nio.ByteBuffer src,
long timeout,
java.util.concurrent.TimeUnit unit)
throws java.io.IOException,
SuspendExecution
This writes a sequence of bytes to this channel from the given buffer. The returned result is the number of bytes written.
If a timeout is specified and the timeout elapses before the operation
completes then the method throws the exception InterruptedByTimeoutException. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been written, or will
not be written to the channel from the given buffer, then further attempts
to write to the channel will cause an unspecific runtime exception to be
thrown.
Otherwise this method works in the same manner as the write(ByteBuffer) method.
src - The buffer from which bytes are to be retrievedtimeout - The maximum time for the I/O operation to completeunit - The time unit of the timeout argumentWritePendingException - If a write operation is already in progress on this channelNotYetConnectedException - If this channel is not yet connectedShutdownChannelGroupException - If the channel group has terminatedjava.nio.channels.InterruptedByTimeoutException - If a timeout is specified and the timeout elapses before the operation completesjava.io.IOExceptionSuspendExecution@Suspendable public abstract long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException
read in interface java.nio.channels.ScatteringByteChannelNotYetConnectedException - If this channel is not yet connectedjava.io.IOException@Suspendable public abstract long read(java.nio.ByteBuffer[] dsts) throws java.io.IOException
read in interface java.nio.channels.ScatteringByteChannelNotYetConnectedException - If this channel is not yet connectedjava.io.IOException@Suspendable public abstract int read(java.nio.ByteBuffer dst) throws java.io.IOException
read in interface java.nio.channels.ReadableByteChannelNotYetConnectedException - If this channel is not yet connectedjava.io.IOException@Suspendable public abstract long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException
write in interface java.nio.channels.GatheringByteChannelNotYetConnectedException - If this channel is not yet connectedjava.io.IOException@Suspendable public abstract long write(java.nio.ByteBuffer[] srcs) throws java.io.IOException
write in interface java.nio.channels.GatheringByteChannelNotYetConnectedException - If this channel is not yet connectedjava.io.IOException@Suspendable public abstract int write(java.nio.ByteBuffer src) throws java.io.IOException
write in interface java.nio.channels.WritableByteChannelNotYetConnectedException - If this channel is not yet connectedjava.io.IOExceptionpublic abstract boolean isOpen()
isOpen in interface java.nio.channels.Channelpublic abstract void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channeljava.io.IOExceptionpublic abstract FiberSocketChannel shutdownInput() throws java.io.IOException
Once shutdown for reading then further reads on the channel will
return -1, the end-of-stream indication. If the input side of the
connection is already shutdown then invoking this method has no effect.
The effect on an outstanding read operation is system dependent and
therefore not specified. The effect, if any, when there is data in the
socket receive buffer that has not been read, or data arrives subsequently,
is also system dependent.
NotYetConnectedException - If this channel is not yet connectedjava.nio.channels.ClosedChannelException - If this channel is closedjava.io.IOException - If some other I/O error occurspublic abstract FiberSocketChannel shutdownOutput() throws java.io.IOException
Once shutdown for writing then further attempts to write to the
channel will throw ClosedChannelException. If the output side of
the connection is already shutdown then invoking this method has no
effect. The effect on an outstanding write operation is system dependent
and therefore not specified.
NotYetConnectedException - If this channel is not yet connectedjava.nio.channels.ClosedChannelException - If this channel is closedjava.io.IOException - If some other I/O error occurspublic abstract java.net.SocketAddress getRemoteAddress()
throws java.io.IOException
Where the channel is bound and connected to an Internet Protocol
socket address then the return value from this method is of type InetSocketAddress.
null if the channel's socket is not connectedjava.nio.channels.ClosedChannelException - If the channel is closedjava.io.IOException - If an I/O error occurspublic abstract FiberSocketChannel bind(java.net.SocketAddress local) throws java.io.IOException
bind in interface java.nio.channels.NetworkChannelConnectionPendingException - If a connection operation is already in progress on this channelAlreadyBoundExceptionUnsupportedAddressTypeExceptionjava.nio.channels.ClosedChannelExceptionjava.io.IOExceptionpublic abstract <T> FiberSocketChannel setOption(java.net.SocketOption<T> name, T value) throws java.io.IOException
setOption in interface java.nio.channels.NetworkChanneljava.lang.IllegalArgumentExceptionjava.nio.channels.ClosedChannelExceptionjava.io.IOExceptionpublic abstract java.net.SocketAddress getLocalAddress()
throws java.io.IOException
getLocalAddress in interface java.nio.channels.NetworkChanneljava.io.IOExceptionpublic abstract <T> T getOption(java.net.SocketOption<T> name)
throws java.io.IOException
getOption in interface java.nio.channels.NetworkChanneljava.io.IOExceptionpublic abstract java.util.Set<java.net.SocketOption<?>> supportedOptions()
supportedOptions in interface java.nio.channels.NetworkChannelpublic abstract java.lang.Object provider()
null.