home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIPHEFT062001.ISO / exe / O502java.exe / OPERA.JAR / opera / OperaURLConnection.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-01-10  |  4.1 KB  |  181 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.             super.connected = false;
  98.             throw new FileNotFoundException(super.url.toString());
  99.          }
  100.  
  101.          super.connected = true;
  102.       }
  103.  
  104.       return this.field_0;
  105.    }
  106.  
  107.    public int getContentLength() {
  108.       if (!super.connected) {
  109.          try {
  110.             this.connect();
  111.          } catch (Exception var2) {
  112.          }
  113.       }
  114.  
  115.       return this.field_0 != null ? this.field_0.getContentLength() : 0;
  116.    }
  117.  
  118.    public OutputStream getOutputStream() throws IOException {
  119.       super.method = "POST";
  120.       if (!super.connected) {
  121.          this.connect();
  122.       }
  123.  
  124.       return this.field_1;
  125.    }
  126.  
  127.    public String getHeaderField(String var1) {
  128.       return super.getHeaderField(var1);
  129.    }
  130.  
  131.    public String getRequestProperty(String var1) {
  132.       return (String)this.req_props.get(var1);
  133.    }
  134.  
  135.    public void setRequestProperty(String var1, String var2) {
  136.       if (var1.compareToIgnoreCase("Content-length") != 0) {
  137.          this.req_props.put(var1, var2);
  138.       }
  139.  
  140.    }
  141.  
  142.    public void disconnect() {
  143.    }
  144.  
  145.    public boolean usingProxy() {
  146.       return false;
  147.    }
  148.  
  149.    protected void finalize() throws Throwable {
  150.       if (this.field_0 != null) {
  151.          this.field_0 = null;
  152.          OperaInputStream.removeStream(this.istream_id);
  153.       }
  154.  
  155.       if (this.field_1 != null) {
  156.          this.field_1 = null;
  157.          OperaOutputStream.removeStream(this.ostream_id);
  158.       }
  159.  
  160.       super.finalize();
  161.    }
  162.  
  163.    protected String makeExtraHeaders() {
  164.       String var1 = "";
  165.       Enumeration var2 = this.req_props.keys();
  166.       Enumeration var3 = this.req_props.elements();
  167.  
  168.       while(var2.hasMoreElements()) {
  169.          var1 = var1.concat((String)var2.nextElement());
  170.          String var4 = (String)var3.nextElement();
  171.          if (var4 != null) {
  172.             var1 = var1.concat(": " + var4 + "\r\n");
  173.          } else {
  174.             var1 = var1.concat("\r\n");
  175.          }
  176.       }
  177.  
  178.       return var1;
  179.    }
  180. }
  181.