I need to pass a (direct) ByteBuffer
to native functions that will read/write from/into the buffer. Once these operations are completed, I would like to access the ByteBuffer
from Java code using the regular functions; in particular, limit()
and position()
should reflect the current state of the buffer.
Since JNI will use GetDirectBufferAddress()
to directly access the underlying buffer, I am assuming I should call flip ()
/ limit()
/ position()
after I am done reading / writing. However, I have been unable to make this work. For example, after I read a couple of bytes into the buffer from C, and set its limit and position accordingly, I cannot query those bytes from Java; Java's idea of the buffer limit and position are not consistent with what I did in the C code.
Can anybody point me to a working example of this? Thanks in advance.