tags:

views:

542

answers:

2

I have a object store in Java. My C program stores data (in form of char array) in java. Now I wish to retrieve data from my store. I cannot find any function call that returns me an char array. How can I do this?

A: 

You need to use one of the various API's provided by JNI, probably GetCharArrayElements().

Following is an example, taken from working code which retrieves a byte array from Java into C (the code is a function which is invoked by Java, but the mechanics are identical).

JNIEXPORT void JNICALL Java_xxx_jniEnqueue(JNIEnv *jep,jobject thsObj,
 jlong handle, jbyteArray jvaKey, jint jvaKeyOfs, jint jvaKeyLen, jbyteArray jvaData, jint jvaDtaOfs, jint jvaDtaLen) {
    jbyte            *jniKey,*jniData;
    jthrowable       escObj;

    jniKey=(*jep)->GetByteArrayElements(jep,jvaKey,0);
    jniData=(*jep)->GetByteArrayElements(jep,jvaData,0);
    ...
    memcpy(odp->enqpfx->Msg,jniKey+jvaKeyOfs,(vuns)jvaKeyLen);              /* key badly named Msg */
    ...
    // enqueue data using key
    if(/* enqueue failed */) {
        (*jep)->ReleaseByteArrayElements(jep,jvaKey ,jniKey ,JNI_ABORT); /* abort to not copy back */
        (*jep)->ReleaseByteArrayElements(jep,jvaData,jniData,JNI_ABORT); /* abort to not copy back */
        throwEscapeObject(jep,escObj);
        return;
        }
    (*jep)->ReleaseByteArrayElements(jep,jvaKey ,jniKey ,JNI_ABORT); /* abort to not copy back */
    (*jep)->ReleaseByteArrayElements(jep,jvaData,jniData,JNI_ABORT); /* abort to not copy back */
    }
Software Monkey
A: 

Created a new question regarding it. Link: Retrieving byte array of unknow length from Java store

cornerback84