home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 February / GAME_2.ISO / utilities / Opera 5.01 / Opera501_final_nonjava.exe / OPERA.JAR / opera / OperaURLConnection.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-12-12  |  4.1 KB  |  179 lines

  1. package opera;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7. import java.net.HttpURLConnection;
  8. import java.net.URL;
  9. import java.util.Enumeration;
  10. import java.util.Hashtable;
  11.  
  12. public class OperaURLConnection extends HttpURLConnection {
  13.    // $FF: renamed from: is opera.OperaInputStream
  14.    private OperaInputStream field_0 = null;
  15.    private int istream_id = -1;
  16.    // $FF: renamed from: os opera.OperaOutputStream
  17.    private OperaOutputStream field_1 = null;
  18.    private int ostream_id = -1;
  19.    private Hashtable req_props = new Hashtable();
  20.  
  21.    protected OperaURLConnection(URL var1) {
  22.       super(var1);
  23.    }
  24.  
  25.    public void connect() throws IOException {
  26.       if (!super.connected) {
  27.          SecurityManager var1 = System.getSecurityManager();
  28.          if (var1 != null) {
  29.             var1.checkConnect(super.url.getHost(), super.url.getPort());
  30.          }
  31.  
  32.          try {
  33.             this.field_0 = new OperaInputStream(this);
  34.             this.field_1 = new OperaOutputStream(this);
  35.             this.istream_id = OperaInputStream.addStream(this.field_0);
  36.             this.ostream_id = OperaOutputStream.addStream(this.field_1);
  37.             this.field_1.istream_id = this.istream_id;
  38.             if (super.method.compareTo("POST") == 0) {
  39.                Object var2 = PluginContext.opera_mutex;
  40.                synchronized(var2) {
  41.                   this.nativeConnect(super.url.toString(), super.method, this.ostream_id);
  42.                }
  43.  
  44.                super.connected = true;
  45.             } else {
  46.                Object var11 = PluginContext.opera_mutex;
  47.                synchronized(var11) {
  48.                   this.nativeConnect(super.url.toString(), super.method, this.istream_id);
  49.                }
  50.  
  51.                try {
  52.                   OperaInputStream var4 = this.field_0;
  53.                   synchronized(var4) {
  54.                      this.field_0.wait();
  55.                   }
  56.                } catch (InterruptedException var7) {
  57.                   Thread.currentThread().interrupt();
  58.                }
  59.  
  60.                if (this.field_0.getResponse() != 200) {
  61.                   super.connected = false;
  62.                } else {
  63.                   super.connected = true;
  64.                }
  65.             }
  66.          } catch (Exception var10) {
  67.             ((Throwable)var10).printStackTrace(System.err);
  68.          }
  69.  
  70.          if (!super.connected) {
  71.             throw new IOException("Connection failed.");
  72.          }
  73.       }
  74.  
  75.    }
  76.  
  77.    private native void nativeConnect(String var1, String var2, int var3);
  78.  
  79.    public InputStream getInputStream() throws IOException {
  80.       if (!super.connected) {
  81.          this.connect();
  82.       }
  83.  
  84.       if (super.method.compareTo("POST") == 0) {
  85.          if (this.field_0.getResponse() == -1) {
  86.             try {
  87.                OperaInputStream var1 = this.field_0;
  88.                synchronized(var1) {
  89.                   this.field_0.wait();
  90.                }
  91.             } catch (InterruptedException var4) {
  92.                Thread.currentThread().interrupt();
  93.             }
  94.          }
  95.  
  96.          if (this.field_0.getResponse() != 200) {
  97.             System.out.println("HTTP Response: " + this.field_0.getResponse());
  98.             super.connected = false;
  99.             throw new FileNotFoundException(super.url.toString());
  100.          }
  101.  
  102.          super.connected = true;
  103.       }
  104.  
  105.       return this.field_0;
  106.    }
  107.  
  108.    public int getContentLength() {
  109.       if (!super.connected) {
  110.          try {
  111.             this.connect();
  112.          } catch (Exception var2) {
  113.          }
  114.       }
  115.  
  116.       return this.field_0 != null ? this.field_0.getContentLength() : 0;
  117.    }
  118.  
  119.    public OutputStream getOutputStream() throws IOException {
  120.       super.method = "POST";
  121.       if (!super.connected) {
  122.          this.connect();
  123.       }
  124.  
  125.       return this.field_1;
  126.    }
  127.  
  128.    public String getHeaderField(String var1) {
  129.       return super.getHeaderField(var1);
  130.    }
  131.  
  132.    public String getRequestProperty(String var1) {
  133.       return (String)this.req_props.get(var1);
  134.    }
  135.  
  136.    public void setRequestProperty(String var1, String var2) {
  137.       this.req_props.put(var1, var2);
  138.    }
  139.  
  140.    public void disconnect() {
  141.    }
  142.  
  143.    public boolean usingProxy() {
  144.       return false;
  145.    }
  146.  
  147.    protected void finalize() throws Throwable {
  148.       if (this.field_0 != null) {
  149.          this.field_0 = null;
  150.          OperaInputStream.removeStream(this.istream_id);
  151.       }
  152.  
  153.       if (this.field_1 != null) {
  154.          this.field_1 = null;
  155.          OperaOutputStream.removeStream(this.ostream_id);
  156.       }
  157.  
  158.       super.finalize();
  159.    }
  160.  
  161.    protected String makeExtraHeaders() {
  162.       String var1 = "";
  163.       Enumeration var2 = this.req_props.keys();
  164.       Enumeration var3 = this.req_props.elements();
  165.  
  166.       while(var2.hasMoreElements()) {
  167.          var1 = var1.concat((String)var2.nextElement());
  168.          String var4 = (String)var3.nextElement();
  169.          if (var4 != null) {
  170.             var1 = var1.concat(": " + var4 + "\n\r");
  171.          } else {
  172.             var1 = var1.concat("\n\r");
  173.          }
  174.       }
  175.  
  176.       return var1;
  177.    }
  178. }
  179.