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:
Limit: All read and write operations to buffer will be capped with the value of the limit variable.
Position: Represents the position of the current cursor when reading and writing to a buffer.
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