The difference of Flip,rewind,clear method in Java.nio.ByteBuffer

Source: Internet
Author: User
Tags rewind

The read and write operations to the buffer first know the lower, upper, and current position of the buffer. The values of the following variables are essential for some operations in the buffer class:
    1. Limit: All read and write operations to buffer will be capped with the value of the limit variable.

    2. Position: Represents the position of the current cursor when reading and writing to a buffer.

    3. Capacity: Represents the maximum capacity of the buffer (typically when a new buffer is created, the value of limit and the value of capacity are equal by default).

Flip, rewind, and clear are the three ways to set these values.

Clear method

Public FinalBuffer Clear ()
{
Position = 0; //Reset the current read and write location
Limit = capacity;
Mark =-1; //Unmark
return this;
}

The clear method empties the buffer, typically called when the buffer is being re-written .


Flip method

Public FinalBuffer Flip (){
Limit = position;
Position = 0;
Mark = -1;
return this;
}


Reverses the buffer. Set the limit to the current location first, and then set the location to 0. If a tag is already defined, the token is discarded. Often used in conjunction with the Compact method. Typically, the flip method is called when the data is ready to be read from the buffer .


Rewind method

1 Public FinalBuffer Rewind (){
2position= 0;
3Mark= -1;
4    return This;
5}


All three of these methods use the final modifier, and all subclasses of java.nio.Buffer use the same flip, clear, and rewind mechanisms.



From for notes (Wiz)

The difference of Flip,rewind,clear method in Java.nio.ByteBuffer

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.