New<PrimitiveType>Array Routines - NewShortArray
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 NewShortArray
env
: the JNI interface pointer.length
: the array length.RETURNS of NewShortArray
Returns a Java array, or
Example of NewShortArrayNULL
if the array cannot be constructed.jshortArray Java_com_mycom_speex_SpeexEncodingActivity_decode(JNIEnv * env,
jobject jobj, jcharArray inputCharData) {
jshortArray ret;
jchar * inputArrayElements = (*env)->GetCharArrayElements(env,
inputCharData, 0);
/*Flush all the bits in the struct so we can decode a new frame*/
speex_bits_reset(&decod_bits);
/*Copy the bits to an array of char that can be written*/
nbBytes = speex_bits_nbytes(&decod_bits);
ret = (jshortArray)((*env)->NewShortArray(env, nbBytes));
jshort * arrayElements = (*env)->GetShortArrayElements(env, ret, 0);
speex_bits_read_from(&decod_bits,(char *) inputArrayElements, nbBytes);
/*Decode the frame*/
speex_decode_int(decod_state, &decod_bits, arrayElements);
(*env)->ReleaseCharArrayElements(env, inputCharData, inputArrayElements,
JNI_ABORT);
(*env)->ReleaseShortArrayElements(env, ret, arrayElements, 0);
return ret;
}