• Post Reply Bookmark Topic Watch Topic
  • New Topic

ByteBuffer methods: flip() vs rewind()  RSS feed

 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am aware that flip() set the current buffer position to 0 and set the limit to the previous buffer position whereas rewind() just set the current buffer position to 0.

In the following code, either I use rewind() or flip() i get the same result.



Could you provide me with a real example where the difference of these 2 methods really matters? Thanks in advance.
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I got it. After having understood that the real use of a ByteBuffer is interacting with a FileChannel (or with a IO/Channel in general). After having read the channel into the buffer the method flip() restore the position to zero and set the limit to the latest position occupied. In that way the buffer will be ready to be read itself. While rewind() just set the position to zero for rereading after having already been read.

Bottom line: solved.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done and thank you for the explanation.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!