Java NIO Buffer

Source: Internet
Author: User

Java NIO buffer is used to interact with the Java NIO Channel. We read the data in the channel into buffer and write the data in buffer to the channel.

Buffer is essentially a piece of memory, we write the data first and then read it. Writing is to write the data in the channel into buffer and read it to read the data in buffer. The Java NiO buffer object is to manage this memory, simplifying the operation of this block of memory.

1 basic use of Java NIO buffer

4 Steps:

The first step is to write the data in the channel into the NIO buffer;

In the second step, the flip () function of buffer is called to convert the write mode of buffer into read mode;

The third step is to read the data from the NIO buffer;

Fourth step, call the buffer clear method.

capacity, position and limit of 2 NiO buffer

The capacity of the NIO buffer is fixed. Position is the location of read and write, each read and write an element, it will automatically increase by 1, call the flip () function will reset this position to 0. Limit is the total size of the data that is written, and when it is read again, it knows where to read it, and when it does, it sets the limit to the current position when it calls the flip () function.

Java NIO Buffer

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.