title: Manipulation of ByteBuffer from JNI
body: <p>I need to pass a (direct) <code>ByteBuffer</code> to native functions that will read/write from/into the buffer. Once these operations are completed, I would like to access the <code>ByteBuffer</code> from Java code using the regular functions; in particular, <code>limit()</code> and <code>position()</code> should reflect the current state of the buffer.</p>
  
  <p>Since JNI will use <code>GetDirectBufferAddress()</code> to directly access the underlying buffer, I am assuming I should call <code>flip ()</code> / <code>limit()</code> / <code>position()</code> 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.</p>
  
  <p>Can anybody point me to a working example of this? Thanks in advance.</p>