• Post Reply Bookmark Topic Watch Topic
  • New Topic

ByteBuffer

 
Ahmed Basheer
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not getting this flip business in NIO buffer. I am trying to use ByteBuffer as circular buffer. Now After I read 20 bytes into ByteBuffer, I only want to get 10 bytes from bytes and then continue reading. But problem is that when I have to get the 10 bytes I flip the buffer, position is set to 0, then the subsequent reads overwite the remaing 10 bytes in the ByteBuffer. Which means that when you flip ByteBuffer you have to get all the bytes from it, clear it and read again. So I am guessing that I can't use ByteBuffer as circular buffer.

Does any one had differing opinion? I appreciate your opinions.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use position(int) and capacity(int) to set the buffer to read or write exactly where you want.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!