Java Reference
In-Depth Information
Channel
WritableByteChannel
ReadableByteChannel
Can read data into a buffer
Can write data from a
buffer.
ScatteringByteChannel
ByteChannel
GatheringByteChannel
Can read into muliple
buffers.
Can read data into a buffer and
write data from a buffer.
Can write data from
multiple buffers.
Each arrow points from a given interface to an interface that it implements. The
ByteChannel
interface simply combines the operations specified by the
ReadableByteChannel
and
WritableByteChannel
interface without declaring any additional methods. The
ScatteringByteChannel
interface extends the
ReadableByteChannel
interface by adding
methods that allow data to be read and distributed amongst several separate buffers in a single
operation. The
GatheringByteChannel
adds methods to those of the
WritableByteChannel
to
permit writing from a number of separate buffers in a single operation.
The methods that each channel interface declares are as follows:
Interface
Method and Description
ReadableByteChannel
int read(ByteBuffer input)
Reads bytes from a channel into the buffer specified by
the argument and returns the number of bytes read, or
-1
if the end of the stream is reached.
WritableByteChannel
int write(ByteBuffer output)
Writes bytes from the buffer specified by the argument
to the channel, and returns the number of bytes written.
ByteChannel
This interface just inherits methods from the
ReadableByteChannel
and
WritableByteChannel
interfaces. No additional
methods are declared.
Table continued on following page