• Post Reply Bookmark Topic Watch Topic
  • New Topic

ByteBuffer's rewind()

 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rewind()

The Buffer.rewind() sets the position back to 0, so you can reread all the data in the buffer. The limit remains untouched, thus still marking how many elements (bytes, chars etc.) that can be read from the Buffer.


I don't understand why we will re-read same bytes which we have already printed ? or does it mean we can overwrite next read into buffer like it happens with clear() ?


 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
meeta gaur wrote:I don't understand why we will re-read same bytes which we have already printed ?

You can do other things with the contents of a ByteBuffer besides print them.
The javadoc shows an example of how it could be used.

 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
meeta gaur wrote:I don't understand why we will re-read same bytes which we have already printed ?

You can do other things with the contents of a ByteBuffer besides print them.
The javadoc shows an example of how it could be used.



Actually i want to ask that, will rewind overwrite old data ? as it happens with clear(). If it is, then only difference between rewind() and clear() is that clear() changes limit to capacity while rewind() keeps it unchanged.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
meeta gaur wrote:Actually i want to ask that, will rewind overwrite old data ? as it happens with clear(). If it is, then only difference between rewind() and clear() is that clear() changes limit to capacity while rewind() keeps it unchanged.

So you can either read the Javadoc or write a simple test program. Experimentation is a much better learning aid than simple being given the answer.
 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
meeta gaur wrote:Actually i want to ask that, will rewind overwrite old data ? as it happens with clear(). If it is, then only difference between rewind() and clear() is that clear() changes limit to capacity while rewind() keeps it unchanged.

So you can either read the Javadoc or write a simple test program. Experimentation is a much better learning aid than simple being given the answer.

Ok thank you, i will try to get it somehow.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!