Background
I'm working with byte arrays in JNI. And I can't get length of jbyteArray. I'm writing code in eclipse in Windows 7.
Java code:
private native int Enroll( byte[] pSeed );
JNI code:
In JNI I have a struct that have two members unsigned long length and unsigned char data[1]
typedef struct blobData_s {
unsigned long length;
unsigned char data[1];
} blobData_t;
Now as my JNI function get as argument jbyteArray jpSeed i want to get the length of jpSeed and set it as length member of struct.
JNIEXPORT jint JNICALL Java_com_Test_Enroll( JNIEnv* env, jobject thiz, jbyteArray jpSeed ){
blobData_t* bd = malloc( sizeof(blobData_t) );
bd->length = **Question 1**
bd->data[1] = jbyteArray;
}
Question 1: How I can get the length of jpSeed in JNI ?
Question 2: Will this code works correct bd.data[1] = jbyteArray; ?
解决方案
You can use GetArrayLength(JNIEnv* env, jbyteArray array) Read here.
Not sure what you want to do, I assume you want the content of jpSeed in bd.data[1].
Anyways, accessing the contents of a byte array, should be done with GetByteArrayElements(...).