java.nio.channels
Defines channels, which represent connections to entities that are capable of performing I/O operations, such as files and sockets; defines selectors, for multiplexed, non-blocking I/O operations.| Channels | Description |
|---|---|
Channel |
A nexus for I/O operations |
ReadableByteChannel |
Can read into a buffer |
ScatteringByteChannel |
Can read into a sequence of buffers |
WritableByteChannel |
Can write from a buffer |
GatheringByteChannel |
Can write from a sequence of buffers |
ByteChannel |
Can read/write to/from a buffer |
SeekableByteChannel |
A ByteChannel connected to an entity that contains a variable-length
sequence of bytes |
AsynchronousChannel |
Supports asynchronous I/O operations. |
AsynchronousByteChannel |
Can read and write bytes asynchronously |
NetworkChannel |
A channel to a network socket |
MulticastChannel |
Can join Internet Protocol (IP) multicast groups |
Channels |
Utility methods for channel/stream interoperation |
A channel represents an open connection to an entity such as a
hardware device, a file, a network socket, or a program component that is
capable of performing one or more distinct I/O operations, for example reading
or writing. As specified in the Channel interface,
channels are either open or closed, and they are both asynchronously
closeable and interruptible.
The Channel interface is extended by several
other interfaces.
The ReadableByteChannel interface specifies a
read method that reads bytes
from the channel into a buffer; similarly, the WritableByteChannel interface specifies a write method that writes bytes
from a buffer to the channel. The ByteChannel
interface unifies these two interfaces for the common case of channels that can
both read and write bytes. The SeekableByteChannel
interface extends the ByteChannel interface with methods to query and modify the channel's
current position, and its size.
The ScatteringByteChannel and GatheringByteChannel interfaces extend the ReadableByteChannel and WritableByteChannel interfaces, respectively, adding read and write methods that take a
sequence of buffers rather than a single buffer.
The NetworkChannel interface specifies methods
to bind the channel's socket,
obtain the address to which the socket is bound, and methods to get and set socket options. The MulticastChannel interface specifies methods to join
Internet Protocol (IP) multicast groups.
The Channels utility class defines static methods
that support the interoperation of the stream classes of the java.io package with the channel classes of this package. An appropriate
channel can be constructed from an InputStream or an OutputStream, and conversely an InputStream or an
OutputStream can be constructed from a channel. A Reader can be constructed that uses a given charset to decode bytes
from a given readable byte channel, and conversely a Writer can
be constructed that uses a given charset to encode characters into bytes an