New<PrimitiveType>Array Routines - NewByteArray
ArrayType New<PrimitiveType>Array
(JNIEnv *env, jsize length);
A family of operations used to construct a new primitive array object. Table 4-8 describes the specific primitive array constructors. You should replace New<PrimitiveType>Array with one of the actual primitive array constructor routine names from the following table, and replace ArrayType with the corresponding array type for that routine.
Table 4-8a New<PrimitiveType>Array Family of Array Constructors
LINKAGE:
Indices in the JNIEnv interface function table.
Table 4-8b New<PrimitiveType>Array Family of Array Constructors
New<PrimitiveType>Array Routines
|
Index
|
---|---|
NewBooleanArray() |
175
|
NewByteArray() |
176
|
NewCharArray() |
177
|
NewShortArray() |
178
|
NewIntArray() |
179
|
NewLongArray() |
180
|
NewFloatArray() |
181
|
NewDoubleArray() |
182
|
PARAMETERS of NewByteArray
env
: the JNI interface pointer.length
: the array length.RETURNS of NewByteArray
Returns a Java array, or
Example of NewByteArrayNULL
if the array cannot be constructed.
void add(char* key, char* value, int length)
{
jstring j_key = (*env)->NewStringUTF(env, key);
jbyteArray j_value = (*env)->NewByteArray(env, length);
(*env)->SetByteArrayRegion(env, j_value, 0, length, (jbyte *)value);
ret = (*env)->CallStaticBooleanMethod(env, j_store, method_id, j_key, j_value);
if(j_value != null)
{
(*env)->ReleaseByteArrayElements(env, j_value, (jbyte *)value, 0);
}
if(j_key != null)
{
(*env)->ReleaseStringUTFChars(env, j_key, key);
}
}