21

I've got a method:

public native void doSomething(ByteBuffer in, ByteBuffer out);

Generated by javah C/C++ header of this method is:

JNIEXPORT void JNICALL Java__MyClass_doSomething (JNIEnv *, jobject, jobject, jobject, jint, jint);

How can I get a data array from jobject (that is a ByteBuffer instance) ?

Arek
  • 3,106
  • 3
  • 23
  • 32

1 Answers1

33

Assuming you allocated the ByteBuffer using ByteBuffer.allocateDirect() you can use GetDirectBufferAddress

jbyte* bbuf_in;  jbyte* bbuf_out;

bbuf_in = (*env)->GetDirectBufferAddress(env, buf1);  
bbuf_out= (*env)->GetDirectBufferAddress(env, buf2); 
Matt
  • 659
  • 6
  • 11
stacker
  • 68,052
  • 28
  • 140
  • 210