Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I get a byte array from an object passed into the JNI?

843829May 9 2002 — edited May 9 2002
This is what my java code looks like:

public class streamedData
{
protected byte[] m_value = null;

public byte[] getByteArray ()
{
return m_value;
}
/* code not pertaining to this question snipped. */
};

jclass streamedDataClass = env->GetObjectClass(jstreamedData);

// Get methodIDs for the various NPKI_Extension methods
value = env->GetMethodID(streamedDataClass, "getByteArray", "()[B");

lstreamedData->value = (unsigned char *)malloc (lstreamedData->length);
if (lstreamedData->value == NULL)
{
return INSUFFICIENT_MEMORY;
}
memset (lstreamedData->value, 0, lstreamedData->length);
memcpy (lstreamedData->value, env->CallByteMethodA(streamedDataClass, value, NULL), lstreamedData->length);
}

This is not working.
My question is, how do I get a copy of or read m_value in the JNI layer? Do I have to make the byte array public and access it as a field ID?

Any help would be appreciated. Why oh why can't there be a CallByteArrayMethod????

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2002
Added on May 9 2002
1 comment
4,201 views