Yahie
Yahie

Reputation: 13

Get index from bytebuffer

I have to read a byteBuffer in Java. I a m using byteBuffer.get() but when I read a specific value, I have to get the offset in the byteBuffer. How can I do that ?

For example

byte name = byteBuffer.get();
byte location = byteBuffer.get();

for (int i=1; i<16; i++){
    //Here I want to get the offset in the byteBuffer like bytebuffer.getOffsset() or something like that
    MyObject myObject = new MyObject();
    byteBuffer.get(myObject);
}

I want to get all offset for each "MyObject" Is there something to do to get these offsets ?

Upvotes: 0

Views: 3445

Answers (1)

Joop Eggen
Joop Eggen

Reputation: 109567

int offset = byteBuffer.position();

This is a method of the Buffer class, hence you probably overlooked it.

Upvotes: 4

Related Questions