Some channels may not allow more than one read or write to be outstanding
at any given time. If a thread invokes a read method before a previous read
operation has completed then a ReadPendingException
will be thrown.
Similarly, if a write method is invoked before a previous write has completed
then WritePendingException
is thrown. Whether or not other kinds of
I/O operations may proceed concurrently with a read operation depends upon
the type of the channel.
Note that ByteBuffers
are not safe for use by
multiple concurrent threads. When a read or write operation is initiated then
care must be taken to ensure that the buffer is not accessed until the
operation completes.
Channels#newInputStream(AsynchronousByteChannel)
, Channels#newOutputStream(AsynchronousByteChannel)
Modifier and Type | Method and Description |
---|---|
public < The type of the attachment A> void | read(ByteBuffer
The buffer into which bytes are to be transferred dst, A The object to attach to the I/O operation; can be attachment, CompletionHandler<Integer, ? super A> null The completion handler handler)Reads a sequence of bytes from this channel into the given buffer. |
public Future | Returns: A Future representing the result of the operationThe buffer into which bytes are to be transferred dst)Reads a sequence of bytes from this channel into the given buffer. |
public < The type of the attachment A> void | write(ByteBuffer
The buffer from which bytes are to be retrieved src, A The object to attach to the I/O operation; can be attachment, CompletionHandler<Integer, ? super A> null The completion handler object handler)Writes a sequence of bytes to this channel from the given buffer. |
public Future | Returns: A Future representing the result of the operationThe buffer from which bytes are to be retrieved src)Writes a sequence of bytes to this channel from the given buffer. |
read | back to summary |
---|---|
public <A> void read(ByteBuffer dst, A attachment, CompletionHandler<Integer, ? super A> handler) Reads a sequence of bytes from this channel into the given buffer. This method initiates an asynchronous read operation to read a
sequence of bytes from this channel into the given buffer. The The read operation may read up to r bytes from the channel,
where r is the number of bytes remaining in the buffer, that is,
Suppose that a byte sequence of length n is read, where
Buffers are not safe for use by multiple concurrent threads so care should be taken to not access the buffer until the operation has completed. This method may be invoked at any time. Some channel types may not
allow more than one read to be outstanding at any given time. If a thread
initiates a read operation before a previous read operation has
completed then a
|
read | back to summary |
---|---|
public Future Reads a sequence of bytes from this channel into the given buffer. This method initiates an asynchronous read operation to read a
sequence of bytes from this channel into the given buffer. The method
behaves in exactly the same manner as the
|
write | back to summary |
---|---|
public <A> void write(ByteBuffer src, A attachment, CompletionHandler<Integer, ? super A> handler) Writes a sequence of bytes to this channel from the given buffer. This method initiates an asynchronous write operation to write a
sequence of bytes to this channel from the given buffer. The The write operation may write up to r bytes to the channel,
where r is the number of bytes remaining in the buffer, that is,
Suppose that a byte sequence of length n is written, where
Buffers are not safe for use by multiple concurrent threads so care should be taken to not access the buffer until the operation has completed. This method may be invoked at any time. Some channel types may not
allow more than one write to be outstanding at any given time. If a thread
initiates a write operation before a previous write operation has
completed then a
|
write | back to summary |
---|---|
public Future Writes a sequence of bytes to this channel from the given buffer. This method initiates an asynchronous write operation to write a
sequence of bytes to this channel from the given buffer. The method
behaves in exactly the same manner as the
|