1999-09-08 04:21:03 +04:00
|
|
|
/*
|
1999-11-06 05:47:15 +03: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
|
|
|
*
|
1999-11-06 05:47:15 +03: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,
|
1999-11-06 05:47:15 +03:00
|
|
|
* 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
|
|
|
*/
|
1999-11-21 02:19:40 +03:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
1999-09-08 04:21:03 +04:00
|
|
|
#include "nsIOutputStream.h"
|
1999-09-12 03:47:47 +04:00
|
|
|
#include "org_mozilla_pluglet_mozilla_PlugletOutputStream.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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
env->GetByteArrayRegion(b,off,len,buf);
|
|
|
|
PRUint32 tmp;
|
|
|
|
output->Write(buf,len,&tmp);
|
|
|
|
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) {
|
|
|
|
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) {
|
|
|
|
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) {
|
|
|
|
NS_RELEASE(output);
|
|
|
|
env->SetLongField(jthis, peerFID,0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|