One or three major categories
1, Channels
2, selector and Selectionkey
3. Buffer and its sub-categories
Note: All channel needs to be used in conjunction with the buffer class to implement buffers through the buffer class
The synchronous non-blocking Io,selectablechannel class Configureblocking (Boolean block) method is configured to block without blocking, false is not blocked, and is true by default, directly through channels. (It is known that FileChannel is not configured to block non-blocking because it reads directly through the system IO to the file, there is no blocking and non-blocking distinction)
IO multiplexing can be achieved via selector and Selectionkey
NIO Package Structure:
NIO Packet Interface:
Channels Class Description:
Mainly responsible for the conversion of InputStream and OutputStream to channel, the channel to InputStream, OutputStream, Reader, Writer, classic IO and nio to each other
StaticReadablebytechannel Newchannel (InputStream in)StaticWritablebytechannel Newchannel (outputstream out)Staticinputstream newinputstream (readablebytechannel ch)Staticoutputstream newoutputstream (writablebytechannel ch)StaticReader newreader (Readablebytechannel ch, Charsetdecoder Dec,intminbuffercap)StaticReader newreader (Readablebytechannel ch, String csname)StaticWriter newwriter (Writablebytechannel ch, charsetencoder Enc,intminbuffercap)StaticWriter newwriter (Writablebytechannel ch, String csname)
Interface description
Channel interface: void Close (); Boolean IsOpen ()
Readablebytechannel interface: int read (Bytebuffer DST)
Writablebytechannel interface: int write (Bytebuffer src)
Bytechannel interface: Interface for all of the above interfaces
Scatteringbytechannel interface: Long read (bytebuffer[] dsts), long Read (bytebuffer[] dsts, int offset, int length). Useful when reading different parts of a network protocol, such as the header and body of the HTTP protocol.
A decentralized read operation reads a sequence of bytes into one or more given buffer sequences in a single call. Decentralized reads are often useful when implementing network protocols or file formats, such as grouping data into segments that consist of one or more fixed-length headers, followed by a variable-length body.
Gatheringbytechannel Interface: Long Write (bytebuffer[] srcs), long write (bytebuffer[] srcs, int offset, int length)
A centralized write operation can write a sequence of bytes from one or more given buffer sequences in a single call. Centralized writes are typically useful when implementing network protocols or file formats, such as grouping data into segments that consist of one or more fixed-length headers, followed by a variable-length body.
Interruptiblechannel interface: void Close (). A channel that can be closed and interrupted asynchronously. You can also use the thread's interrupt method to close. Calling close and calling interrupt will throw exception,exception differently, see the API documentation.
Java NiO Learning-Detailed content