How do I get a byte array from an object passed into the JNI?
843829May 9 2002 — edited May 9 2002This 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????