home *** CD-ROM | disk | FTP | other *** search
- package opera;
-
- import java.io.IOException;
- import java.io.OutputStream;
- import java.util.Hashtable;
-
- class OperaOutputStream extends OutputStream {
- private static final int BUFFER_SIZE = 16384;
- private static Hashtable stream_map = new Hashtable();
- private static int next_stream_id = 0;
- private byte[] buffer = new byte[16384];
- private int next_write_byte = 0;
- private int stream_id = -1;
- protected int istream_id = -1;
- private OperaURLConnection connection = null;
-
- protected OperaOutputStream(OperaURLConnection var1) {
- this.connection = var1;
- }
-
- public void write(int var1) throws IOException {
- if (this.buffer == null) {
- throw new IOException();
- } else {
- this.buffer[this.next_write_byte++] = (byte)var1;
- if (this.next_write_byte == 16384) {
- this.flushBuffer();
- }
-
- }
- }
-
- public void flush() throws IOException {
- if (this.buffer == null) {
- throw new IOException();
- } else {
- this.flushBuffer();
- }
- }
-
- public void close() throws IOException {
- if (this.buffer != null) {
- this.write(0);
- this.flushBuffer();
- this.postData(this.istream_id, this.connection.makeExtraHeaders());
- this.connection = null;
- this.buffer = null;
- } else {
- throw new IOException();
- }
- }
-
- private void flushBuffer() {
- if (this.next_write_byte > 0) {
- this.addData(this.buffer, this.next_write_byte);
- this.next_write_byte = 0;
- }
-
- }
-
- private native void postData(int var1, String var2);
-
- private native void addData(byte[] var1, int var2);
-
- protected static int addStream(OperaOutputStream var0) {
- Hashtable var1 = stream_map;
- synchronized(var1) {
- stream_map.put(new Integer(next_stream_id), var0);
- var0.stream_id = next_stream_id++;
- }
-
- return var0.stream_id;
- }
-
- protected static void removeStream(int var0) {
- Hashtable var1 = stream_map;
- synchronized(var1) {
- stream_map.remove(new Integer(var0));
- }
- }
-
- protected static OperaOutputStream getStream(int var0) {
- Hashtable var1 = stream_map;
- synchronized(var1) {
- OperaOutputStream var2 = (OperaOutputStream)stream_map.get(new Integer(var0));
- return var2;
- }
- }
- }
-