env->SetByteArrayRegion(b,off,len,bufElems);
env->SetByteArrayRegion(b,off,retval,bufElems);
JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_nativeRead    (JNIEnv *env, jobject jthis, jbyteArray b, jint off, jint len) {    PRUint32 retval = 0;    nsIInputStream * input = (nsIInputStream*)env->GetLongField(jthis, peerFID);    if (input) {	PR_LOG(PlugletLog::log, PR_LOG_DEBUG,		("PlugletInputStream.nativeRead: stream = %p, off = %i, len = %i\n", input, off, len));    }    if (env->ExceptionOccurred()) {	return retval;    }    if (!input) {        jclass ex = env->FindClass("java/io/IOException");	if (!ex) {  	    return retval;	}	env->ThrowNew(ex,"Stream was closed");	return retval;    }    jbyte * bufElems = (jbyte*) malloc(sizeof(jbyte)*len);    if (!bufElems) {	return retval;	//nb throw OutOfMemory    }    nsresult res;    res = input->Read((char*)bufElems,(PRUint32)len,&retval);    if (NS_FAILED(res)) {	free(bufElems);	return retval;    }    PR_LOG(PlugletLog::log, PR_LOG_DEBUG,	    ("PlugletInputStream.nativeRead: %i bytes read\n", retval));    env->SetByteArrayRegion(b,off,len,bufElems);    free(bufElems);    return retval;}