Unchecked exception thrown when an attempt is made to acquire a lock on a
region of a file that overlaps a region already locked by the same Java
virtual machine, or when another thread is already waiting to lock an
overlapping region of the same file.

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, each of which specifies a new I/O operation.

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 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 and
write them to a given writable byte channel.

The FileChannel class supports the usual
operations of reading bytes from, and writing bytes to, a channel connected to
a file, as well as those of querying and modifying the current file position
and truncating the file to a specific size. It defines methods for acquiring
locks on the whole file or on a specific region of a file; these methods return
instances of the FileLock class. Finally, it defines
methods for forcing updates to the file to be written to the storage device that
contains it, for efficiently transferring bytes between the file and other
channels, and for mapping a region of the file directly into memory. This last
operation creates an instance of the MappedByteBuffer
class, which extends the ByteBuffer class with several
file-related operations.

Multiplexed, non-blocking I/O, which is much more scalable than
thread-oriented, blocking I/O, is provided by selectors, selectable
channels, and selection keys.

A selector is a multiplexor of selectable channels, which in turn are
a special type of channel that can be put into non-blocking mode. To perform
multiplexed I/O operations, one or more selectable channels are first created,
put into non-blocking mode, and registered
with a selector. Registering a channel specifies the set of I/O operations
that will be tested for readiness by the selector, and returns a selection key that represents the
registration.

Once some channels have been registered with a selector, a selection operation can be performed in
order to discover which channels, if any, have become ready to perform one or
more of the operations in which interest was previously declared. If a channel
is ready then the key returned when it was registered will be added to the
selector's selected-key set. The key set, and the keys within it, can
be examined in order to determine the operations for which each channel is
ready. From each key one can retrieve the corresponding channel in order to
perform whatever I/O operations are required.

That a selection key indicates that its channel is ready for some operation
is a hint, but not a guarantee, that such an operation can be performed by a
thread without causing the thread to block. It is imperative that code that
performs multiplexed I/O be written so as to ignore these hints when they prove
to be incorrect.

This package defines selectable-channel classes corresponding to the DatagramSocket, ServerSocket, and Socket classes defined in the java.net package.
Minor changes to these classes have been made in order to support sockets that
are associated with channels. This package also defines a simple class that
implements unidirectional pipes. In all cases, a new selectable channel is
created by invoking the static open method of the corresponding class.
If a channel needs an associated socket then a socket will be created as a side
effect of this operation.

The implementation of selectors, selectable channels, and selection keys
can be replaced by "plugging in" an alternative definition or instance of the
SelectorProvider class defined in the java.nio.channels.spi package. It is not expected that many developers
will actually make use of this facility; it is provided primarily so that
sophisticated users can take advantage of operating-system-specific
I/O-multiplexing mechanisms when very high performance is required.