JNI:如何获得jbyteArray大小 [英] JNI: How to get jbyteArray size

查看:2545
本文介绍了JNI:如何获得jbyteArray大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我使用字节数组中工作的 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;


解决方案

  1. 您可以使用 GetArrayLength(JNIEnv的* ENV,jbyteArray阵列) here.


  2. 不知道你想做什么,我想,你希望 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; ?

解决方案

  1. You can use GetArrayLength(JNIEnv* env, jbyteArray array) Read here.

  2. 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(...).

这篇关于JNI:如何获得jbyteArray大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆