home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2001 February / maximum-cd-2001-02.iso / PowerWare / Opera / Opera5_final_java.exe / OPERA.JAR / opera / OperaOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-01  |  2.0 KB  |  105 lines

  1. package opera;
  2.  
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.util.Hashtable;
  6.  
  7. class OperaOutputStream extends OutputStream {
  8.    private static final int BUFFER_SIZE = 16384;
  9.    private static Hashtable stream_map = new Hashtable();
  10.    private static int next_stream_id = 0;
  11.    private byte[] buffer = new byte[16384];
  12.    private int next_write_byte = 0;
  13.    private int stream_id = -1;
  14.    protected int istream_id = -1;
  15.    private OperaURLConnection connection = null;
  16.  
  17.    protected OperaOutputStream(OperaURLConnection var1) {
  18.       this.connection = var1;
  19.    }
  20.  
  21.    private native void addData(byte[] var1, int var2);
  22.  
  23.    protected static int addStream(OperaOutputStream var0) {
  24.       Hashtable var1 = stream_map;
  25.       synchronized(var1){}
  26.  
  27.       try {
  28.          stream_map.put(new Integer(next_stream_id), var0);
  29.          var0.stream_id = next_stream_id++;
  30.       } catch (Throwable var3) {
  31.          throw var3;
  32.       }
  33.  
  34.       return var0.stream_id;
  35.    }
  36.  
  37.    public void close() throws IOException {
  38.       if (this.buffer != null) {
  39.          this.write(0);
  40.          this.flushBuffer();
  41.          this.postData(this.istream_id, this.connection.makeExtraHeaders());
  42.          this.connection = null;
  43.          this.buffer = null;
  44.       } else {
  45.          throw new IOException();
  46.       }
  47.    }
  48.  
  49.    public void flush() throws IOException {
  50.       if (this.buffer == null) {
  51.          throw new IOException();
  52.       } else {
  53.          this.flushBuffer();
  54.       }
  55.    }
  56.  
  57.    private void flushBuffer() {
  58.       if (this.next_write_byte > 0) {
  59.          this.addData(this.buffer, this.next_write_byte);
  60.          this.next_write_byte = 0;
  61.       }
  62.  
  63.    }
  64.  
  65.    protected static OperaOutputStream getStream(int var0) {
  66.       Hashtable var2 = stream_map;
  67.       synchronized(var2){}
  68.  
  69.       OperaOutputStream var1;
  70.       try {
  71.          var1 = (OperaOutputStream)stream_map.get(new Integer(var0));
  72.       } catch (Throwable var5) {
  73.          throw var5;
  74.       }
  75.  
  76.       return var1;
  77.    }
  78.  
  79.    private native void postData(int var1, String var2);
  80.  
  81.    protected static void removeStream(int var0) {
  82.       Hashtable var1 = stream_map;
  83.       synchronized(var1){}
  84.  
  85.       try {
  86.          stream_map.remove(new Integer(var0));
  87.       } catch (Throwable var3) {
  88.          throw var3;
  89.       }
  90.  
  91.    }
  92.  
  93.    public void write(int var1) throws IOException {
  94.       if (this.buffer == null) {
  95.          throw new IOException();
  96.       } else {
  97.          this.buffer[this.next_write_byte++] = (byte)var1;
  98.          if (this.next_write_byte == 16384) {
  99.             this.flushBuffer();
  100.          }
  101.  
  102.       }
  103.    }
  104. }
  105.