public interface InterruptibleByteChannel
| Modifier and Type | Method and Description |
|---|---|
<A> void |
close(A attachment,
CompletionHandler<Void,? super A> handler)
Closes this channel.
|
<A> void |
read(ByteBuffer target,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
Reads a sequence of bytes from this channel into the given buffer.
|
<A> void |
write(ByteBuffer source,
long timeout,
TimeUnit unit,
A attachment,
CompletionHandler<Integer,? super A> handler)
Writes a sequence of bytes to this channel from the given buffer.
|
<A> void read(ByteBuffer target, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler) throws IllegalArgumentException, ReadPendingException, ShutdownChannelGroupException
This method initiates an asynchronous read operation to read a
sequence of bytes from this channel into the given buffer. The handler parameter is a completion handler that is invoked when the read
operation completes (or fails). The result passed to the completion
handler 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 operation
completes then the operation completes with the 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 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 AsynchronousByteChannel.read(ByteBuffer,Object,CompletionHandler)
method.
A - The attachment typetarget - The buffer into which bytes are to be transferredtimeout - The timeout, or 0L for no timeoutunit - The time unit of the timeout argumentattachment - The object to attach to the I/O operation; can be nullhandler - The handler for consuming the resultIllegalArgumentException - If the timeout parameter is negative or the buffer is
read-onlyReadPendingException - If the channel does not allow more than one read to be outstanding
and a previous read has not completedShutdownChannelGroupException - If the channel is associated with a group that has terminatedUnsupportedOperationException - If the implementation does not support this operation<A> void write(ByteBuffer source, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)
This method initiates an asynchronous write operation to write a
sequence of bytes to this channel from the given buffer. The handler parameter is a completion handler that is invoked when the write
operation completes (or fails). The result passed to the completion
handler is the number of bytes written.
If a timeout is specified and the timeout elapses before the operation
completes then it completes with 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 AsynchronousByteChannel#write(ByteBuffer,Object,CompletionHandler,boolean)
method.
A - The attachment typesource - The buffer from which bytes are to be retrievedtimeout - The timeout, or 0L for no timeoutunit - The time unit of the timeout argumentattachment - The object to attach to the I/O operation; can be nullhandler - The handler for consuming the resultIllegalArgumentException - If the timeout parameter is negativeWritePendingException - If the channel does not allow more than one write to be outstanding
and a previous write has not completedShutdownChannelGroupException - If the channel is associated with a group that has terminatedUnsupportedOperationException - If the implementation does not support this operation<A> void close(A attachment,
CompletionHandler<Void,? super A> handler)
This method otherwise behaves exactly as specified by AsynchronousChannel.close().
A - The attachment typeattachment - The object to attach to the I/O operation; can be nullhandler - The handler for consuming the resultCopyright © 2011. All Rights Reserved.