gecko-dev/java/plugins/jni/org_mozilla_pluglet_mozilla...

125 строки
3.8 KiB
C++
Исходник Обычный вид История

1999-09-08 04:21:03 +04:00
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
1999-09-08 04:21:03 +04:00
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
1999-09-08 04:21:03 +04:00
*
* The Initial Developer of the Original Code is Sun Microsystems,
* Inc. Portions created by Sun are
* Copyright (C) 1999 Sun Microsystems, Inc. All
* Rights Reserved.
*
* Contributor(s):
1999-09-08 04:21:03 +04:00
*/
#include <stdlib.h>
1999-09-08 04:21:03 +04:00
#include "nsIOutputStream.h"
#include "org_mozilla_pluglet_mozilla_PlugletOutputStream.h"
#include "PlugletLog.h"
1999-09-08 04:21:03 +04:00
static jfieldID peerFID = NULL;
/*
* Class: org_mozilla_pluglet_mozilla_PlugletOutputStream
* Method: flush
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_flush
(JNIEnv *env, jobject jthis) {
nsIOutputStream * output = NULL;
output = (nsIOutputStream*)env->GetLongField(jthis, peerFID);
if(!output) {
return;
}
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
("PlugletOutputStream.flush: stream = %p\n", output));
1999-09-08 04:21:03 +04:00
output->Flush();
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletOutputStream
* Method: nativeWrite
* Signature: ([BII)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_nativeWrite
(JNIEnv *env, jobject jthis, jbyteArray b, jint off, jint len) {
jbyte *buf = NULL;
if(!(buf = (jbyte*)malloc(sizeof(jbyte)*len))) {
return; //nb throw OutOfMemoryException
}
nsIOutputStream * output = NULL;
output = (nsIOutputStream*)env->GetLongField(jthis, peerFID);
if(!output) {
return;
}
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
("PlugletOutputStream.nativeWrite: stream = %p, off = %i, len = %i\n", output, off, len));
1999-09-08 04:21:03 +04:00
env->GetByteArrayRegion(b,off,len,buf);
PRUint32 tmp;
output->Write(buf,len,&tmp);
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
("PlugletOutputStream.nativeWrite: %i bytes written\n", tmp));
1999-09-08 04:21:03 +04:00
free(buf);
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletOutputStream
* Method: nativeFinalize
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_nativeFinalize
(JNIEnv *env, jobject jthis) {
/* nb do as in java-dom stuff */
nsIOutputStream * output = (nsIOutputStream*)env->GetLongField(jthis, peerFID);
if(output) {
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
("PlugletOutputStream.nativeFinalize: stream = %p\n", output));
1999-09-08 04:21:03 +04:00
NS_RELEASE(output);
}
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletOutputStream
* Method: nativeInitialize
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_nativeInitialize
(JNIEnv *env, jobject jthis) {
if(!peerFID) {
peerFID = env->GetFieldID(env->GetObjectClass(jthis),"peer","J");
if (!peerFID) {
return;
}
}
nsIOutputStream * output = (nsIOutputStream*)env->GetLongField(jthis, peerFID);
if (output) {
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
("PlugletOutputStream.nativeInitialize: stream = %p\n", output));
1999-09-08 04:21:03 +04:00
output->AddRef();
}
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletOutputStream
* Method: close
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_close
(JNIEnv *env, jobject jthis) {
nsIOutputStream * output = (nsIOutputStream*)env->GetLongField(jthis, peerFID);
if (output) {
PR_LOG(PlugletLog::log, PR_LOG_DEBUG,
("PlugletOutputStream.close: stream = %p\n", output));
1999-09-08 04:21:03 +04:00
NS_RELEASE(output);
env->SetLongField(jthis, peerFID,0);
}
}