Java NIO
Java NIO uses three core classes:
Buffer
: This holds information that is read or written to a channelChannel
: This is a stream-like technique that supports asynchronous read/write operations to a data source/sinkSelector
: This is a mechanism to handle multiple channels in a single thread
Conceptually, buffers and channels work together to process data. As shown in the next figure, data can be moved in either direction between a buffer and a channel:
The channel is connected to some external data source, while the buffer is used internally to process the data. There are several types of channels and buffers. A few of these are listed in the following tables.
The table for channels is as follows:
Channel class |
Purpose |
---|---|
|
This connects to a file |
|
This supports datagram sockets |
|
This supports streaming sockets |
|
This listens for socket requests |
|
This supports a network socket |
|