About those things in nio

For this bytebuffer class, he is actually an array  

bytebuffer.flip() This is a wraparound method (to prepare for writing)

1 is to move currentPoint to 0  

2 is to move endPointer to the end of valid data



There are several attributes in bytebuffer, two of which are important. limit and postion. position starts at 0, equals to the length of the data after filling the data, and limit is the available length of the entire buffer.

bytebuffer.flip(); After that, the position becomes 0 directly, and the limit is directly equal to the position

In this way, the data between position and limit is the data we need to use, but position and limit are attributes required by bytebuffer when put and get, so they need to be restored after use.

The get and put of bytebuffer are not the same as our usual value and set value, he will manipulate the changes of some attributes.


おすすめ

転載: blog.csdn.net/tiandiyinghun/article/details/49181041