Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JNI - native method with ByteBuffer parameter

Tags:

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) ?

like image 705
Arek Avatar asked Apr 20 '10 09:04

Arek


People also ask

What is JNIEnv * env?

jobject NewGlobalRef(JNIEnv *env, jobject obj); Creates a new global reference to the object referred to by the obj argument. The obj argument may be a global or local reference.

What is JNI C++?

JNI is the Java Native Interface. It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++).

What is JNI Bridge?

Introduction to Java Native Interface: Establishing a bridge between Java and C/C++ JNI (Java Native Interface) is a foreign function interface that allows code running on JVM to call (or be called by) native applications. Using JNI, one can call methods written in C/C++ or even access assembly language.

What JNI calls?

In software design, the Java Native Interface (JNI) is a foreign function interface programming framework that enables Java code running in a Java virtual machine (JVM) to call and be called by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages ...


1 Answers

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);  
like image 80
stacker Avatar answered Sep 21 '22 00:09

stacker