Java NiO Learning-Detailed content

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.