JNI:如何获得jbyteArray大小 [英] JNI: How to get jbyteArray size
问题描述
背景
我使用字节数组中工作的的 JNI 的。我不能让 长度的的 jbyteArray 的。我在写code在 蚀的在的 Windows 7的的
的Java code:的
私人原生INT登记(字节[] pSeed);
JNI code:的
在JNI我有有两个成员结构 unsigned long类型的长度
和 unsigned char型数据[1]
typedef结构blobData_s {
无符号长的长度;
unsigned char型数据[1];
} blobData_t;
现在我的JNI函数获取作为参数 jbyteArray jpSeed
我想获得 jpSeed
的长度和设置作为结构的长度成员。
JNIEXPORT jint JNICALL Java_com_Test_Enroll(JNIEnv的* ENV,jobject THIZ,jbyteArray jpSeed){
blobData_t * BD =的malloc(sizeof的(blobData_t));
BD-GT&;长度= **问题1 **
BD->数据[1] = jbyteArray;
}
问题1:我怎样才能获得的 jpSeed
的长度JNI 的
问题2:请问这个code工作正确 bd.data [1] = jbyteArray;
的
-
您可以使用
GetArrayLength(JNIEnv的* ENV,jbyteArray阵列)
读的 here. -
不知道你想做什么,我想,你希望
jpSeed
中的含量bd.data [1]
。
不管怎么说,访问的字节数组的内容,应与GetByteArrayElements(...)完成的。
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
inbd.data[1]
. Anyways, accessing the contents of a byte array, should be done withGetByteArrayElements(...).
这篇关于JNI:如何获得jbyteArray大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!