Get<PrimitiveType>ArrayRegion Routines - GetByteArrayRegion
void Get<PrimitiveType>ArrayRegion
(JNIEnv *env, ArrayType array,
jsize start, jsize len, NativeType *buf);
A family of functions that copies a region of a primitive array into a buffer.
The following table describes the specific primitive array element accessors. You should do the following substitutions:(GetByteArrayRegion)
- Replace Get<PrimitiveType>ArrayRegion with one of the actual primitive element accessor routine names from Table 4-12.
- Replace ArrayType with the corresponding array type.
- Replace NativeType with the corresponding native type for that routine.
Table 4-12a Get<PrimitiveType>ArrayRegion Family of Array Accessor Routines
LINKAGE of GetByteArrayRegion
Indices in the JNIEnv interface function table.
Table 4-12b Get<PrimitiveType>ArrayRegion Family of Array Accessor Routines
PARAMETERS of GetByteArrayRegion
env: the JNI interface pointer.array: a Java array.start: the starting index.len: the number of elements to be copied.buf: the destination buffer.THROWS:
ArrayIndexOutOfBoundsException: if one of the indexes in the region is not valid.
Example of GetByteArrayRegion
JNIEXPORT jbyteArray function(JNIEnv* env, jobject obj, jbyteArray array) {
int length = (*env)->GetArrayLength(env, array);
jbyte data[256];
(*env)->GetByteArrayRegion(env, array, 0, 256, data);
//also tried
//jbyte *data = (jbyte*) (*env)->GetByteArrayElements(env, array, NULL);
}