The flip of buffer and rewind

Source: Internet
Author: User
Tags rewind

In the buffer class, there are two such methods: Flip and rewind. Check out their API documentation to see the following instructions:

Flip

Public final Buffer Flip ()
Flips this buffer. The limit is set to the current position and then the position are set to zero.  If The mark is defined then it's discarded. Rewnd: Public Final Buffer Rewind () Rewinds this buffer. The position is set to zero and the mark is discarded. Description: What is the difference between these three methods for the buffer class? Why do you have these three methods? Let's start with the first question, simply flip: set limit to the current position, set position as the starting position, that is, the 0;clear method, set the position to 0, set limit to buffer capacity, This is the buffer capacity. The rewind method, then, is to set position to 0, which is the initial position. This is the difference between the three of them; hold a chestnut:/* filechannel fc=new FileInputStream ("Demo.txt"). Getchannel ();//demo.txt is a file on your local bytebuffer Buff=bytebuffer.allocate (1024);//1024 of this is the capacity fc.read (buff) of buffer, or read the content read from the stream into buffer//1.flip if you are using Flip,   That is, the position is set to 0,limit to the current position, the output is the content of Demo.txt//buff.flip (); 2.rewind if the rewind, that is, just set the position to 0, and does not change the limit, if the original limit where the output of the file (limit default at the end of the buffer), the output will be the entire buffer content//   Buff.rewind ();  Output buffer, where decoding is required to correctly display System.out.println (Charset.forname ("encoding"). Decode (buff));  System.out.println (); */

The flip of buffer and rewind

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.