Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving byte array of unknown length from Java store
    text
    copied!<p>I already posted a question regarding it, but at that time I haven't have the account. I got a reply but I was still confused and I cannot continue on that thread.</p> <p>I am re posting the question again along with a link to previous conversation.</p> <p><a href="https://stackoverflow.com/questions/1227582/returning-char-array-from-java-to-c-jni/1231585#1231585">Returning char array from java to string - JNI</a></p> <p>The data I am storing in Java is serialized. I make a java function call using following piece of code.</p> <p>The following code assumes that char of C is compatible with byte of Java, because char of Java is of 2 bytes whereas char of C is of 1 byte. The jbyte is also a signed char*</p> <pre><code> //value will be the serialized data void store(char* key, char* value, int val_len) </code></pre> <p>{</p> <pre><code> //consider the jclass and methodid are already initialized jstring j_key = (*env)-&gt;NewStringUTF(env, key); jbyteArray j_value = (*env)-&gt;NewByteArray(env, val_len); (*env)-&gt;SetByteArrayRegion(env, j_value, 0, val_len, (jbyte *)value); //The store method on java side will save the value (as is) in memory (*env)-&gt;CallStaticVoidMethod(j_class, store_method, key, value); (*env)-&gt;ReleaseByteArrayElements(env, j_value, (jbyte *)value, JNI_ABORT); (*env)-&gt;ReleaseStringUTFChars(env, j_key, key); </code></pre> <p>}</p> <p>Once I have saved the data, I use another function to retrieve data from store. At that time i do not know the size of data I am going to retrieve. My API is in C and store is in Java. I will use my C functions to interact with Java. And also there can be multiple threads retrieving data from Java store at same time.</p> <p>I am making calls from C to Java and my control should return to C program after retrieving data. I am a little confuse on how the code will work. How will I get pointer to array (retrieved from java) and then retrieve it using GetByteArrayElements. Remember I dont know the size of data I am going to retrieve before hand and therefore cannot create a byte array using NewByteArray function and later fill it with data in java code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload