title: What is the best way to pass a jbyteArray from (objective-c) JNI to Java?
body: <p>I'm currently retrieving image data from an iSight camera and I'd like to hand it over to Java for processing. I originally tried to put the data in a jbyteArray and return the jbyteArray. This works once per process. Calling the native function a second time will result in an invalid memory access.</p>
  
  <p>Since I'm working with objective-c and Cocoa, I must use the JNF_COCOA_ENTER(...) and JNF_COCOA_EXIT(...) functions. Sadly, if I can't return the jbyteArray because doing so would result in JNF_COCOA_EXIT(...) not getting called. It was suggested to use a direct ByteBuffer to pass the data from JNI land to java land. Unfortunately, all the resources and references I've been using don't outline this straightforwardly enough for my brain to comprehend. I deeply apologize if this is a "duh" moment or has already been asked (I've searched with no luck), but...</p>
  
  <p>1) What is the most efficient way to bring this image data to Java?</p>
  
  <p>2) How should I use the ByteBuffer class to accomplish this? (if relevant)</p>
  
  <p>Thanks!</p>