home *** CD-ROM | disk | FTP | other *** search
/ PC User 2004 August / Disc 1 / PCU0804CD1.iso / software / browsers / files / opera1.exe / OPERA.JAR / com / opera / OperaURLConnection.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-02-12  |  5.5 KB  |  280 lines

  1. package com.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.  
  11. public class OperaURLConnection extends HttpURLConnection {
  12.    // $FF: renamed from: is com.opera.OperaInputStream
  13.    private OperaInputStream field_0 = new OperaInputStream();
  14.    private int istream_id;
  15.    // $FF: renamed from: os com.opera.OperaOutputStream
  16.    private OperaOutputStream field_1 = new OperaOutputStream();
  17.    private int ostream_id;
  18.  
  19.    protected OperaURLConnection(URL var1) {
  20.       super(var1);
  21.       this.istream_id = OperaInputStream.addStream(this.field_0);
  22.       this.ostream_id = OperaOutputStream.addStream(this.field_1);
  23.       this.field_1.istream_id = this.istream_id;
  24.    }
  25.  
  26.    public void connect() throws IOException {
  27.       if (!this.connected) {
  28.          String var1 = this.url.toString();
  29.          if (this.url.getPort() == -1) {
  30.             int var2 = var1.indexOf(":-1");
  31.             if (var2 != -1) {
  32.                StringBuffer var3 = new StringBuffer(var1);
  33.                var3.delete(var2, var2 + 3);
  34.                var1 = var3.toString();
  35.             }
  36.          }
  37.  
  38.          SecurityManager var14 = System.getSecurityManager();
  39.          if (var14 != null) {
  40.             var14.checkConnect(this.url.getHost(), this.url.getPort());
  41.          }
  42.  
  43.          try {
  44.             if (this.method.compareTo("POST") == 0) {
  45.                synchronized(PluginContext.opera_mutex) {
  46.                   this.nativeConnect(var1, this.method, this.ostream_id);
  47.                   this.ostream_id = -1;
  48.                   this.istream_id = -1;
  49.                }
  50.  
  51.                this.connected = true;
  52.             } else if (this.method.compareTo("GET") == 0) {
  53.                synchronized(PluginContext.opera_mutex) {
  54.                   this.nativeConnect(var1, this.method, this.istream_id);
  55.                   this.ostream_id = -1;
  56.                   this.istream_id = -1;
  57.                }
  58.  
  59.                try {
  60.                   synchronized(this.field_0) {
  61.                      if (!this.field_0.isHeaderLoaded()) {
  62.                         this.field_0.wait();
  63.                      }
  64.                   }
  65.                } catch (InterruptedException var10) {
  66.                   Thread.currentThread().interrupt();
  67.                }
  68.  
  69.                this.responseCode = this.field_0.getResponse();
  70.                if (this.responseCode != 200) {
  71.                   this.connected = false;
  72.                } else {
  73.                   this.connected = true;
  74.                }
  75.             } else {
  76.                synchronized(this.field_0) {
  77.                   this.field_0.headerLoaded(0, 200);
  78.                   this.field_0.setEOF();
  79.                }
  80.  
  81.                this.connected = true;
  82.             }
  83.          } catch (Exception var13) {
  84.             var13.printStackTrace(System.err);
  85.          }
  86.  
  87.          if (!this.connected) {
  88.             throw new IOException("Connection failed.");
  89.          }
  90.       }
  91.  
  92.    }
  93.  
  94.    private native void nativeConnect(String var1, String var2, int var3);
  95.  
  96.    public InputStream getInputStream() throws IOException {
  97.       if (!this.connected) {
  98.          this.connect();
  99.       }
  100.  
  101.       if (this.method.compareTo("POST") == 0) {
  102.          if (!this.field_1.isClosed()) {
  103.             this.field_1.close();
  104.          }
  105.  
  106.          if (this.field_0.getResponse() == -1) {
  107.             try {
  108.                synchronized(this.field_0) {
  109.                   this.field_0.wait();
  110.                }
  111.             } catch (InterruptedException var4) {
  112.                Thread.currentThread().interrupt();
  113.             }
  114.          }
  115.  
  116.          if (this.field_0.getResponse() != 200) {
  117.             this.connected = false;
  118.             throw new FileNotFoundException(this.url.toString());
  119.          }
  120.  
  121.          this.connected = true;
  122.       }
  123.  
  124.       return this.field_0;
  125.    }
  126.  
  127.    public String getContentType() {
  128.       return this.getHeaderField("content-type");
  129.    }
  130.  
  131.    public int getContentLength() {
  132.       if (!this.connected) {
  133.          try {
  134.             this.connect();
  135.          } catch (Exception var2) {
  136.          }
  137.       }
  138.  
  139.       return this.field_0 != null ? this.field_0.getContentLength() : 0;
  140.    }
  141.  
  142.    public String getContentEncoding() {
  143.       return this.getHeaderField("content-encoding");
  144.    }
  145.  
  146.    public OutputStream getOutputStream() throws IOException {
  147.       this.method = "POST";
  148.       if (!this.connected) {
  149.          this.connect();
  150.       }
  151.  
  152.       return this.field_1;
  153.    }
  154.  
  155.    public int getHeaderFieldInt(String var1, int var2) {
  156.       String var3 = this.getHeaderField(var1);
  157.       if (var3 != null) {
  158.          try {
  159.             return Integer.parseInt(var3);
  160.          } catch (NumberFormatException var5) {
  161.          }
  162.       }
  163.  
  164.       return var2;
  165.    }
  166.  
  167.    public String getHeaderField(int var1) {
  168.       if (!this.connected) {
  169.          try {
  170.             this.connect();
  171.          } catch (Exception var4) {
  172.             return null;
  173.          }
  174.       }
  175.  
  176.       this.waitForHeaderLoaded();
  177.  
  178.       for(Enumeration var2 = this.field_0.header_fields.elements(); var1 > 0 && var2.hasMoreElements(); --var1) {
  179.          Object var3 = var2.nextElement();
  180.          if (var1 == 1) {
  181.             return (String)var3;
  182.          }
  183.       }
  184.  
  185.       return null;
  186.    }
  187.  
  188.    public String getHeaderFieldKey(int var1) {
  189.       if (!this.connected) {
  190.          try {
  191.             this.connect();
  192.          } catch (Exception var4) {
  193.             return null;
  194.          }
  195.       }
  196.  
  197.       this.waitForHeaderLoaded();
  198.  
  199.       for(Enumeration var2 = this.field_0.header_fields.keys(); var1 > 0 && var2.hasMoreElements(); --var1) {
  200.          Object var3 = var2.nextElement();
  201.          if (var1 == 1) {
  202.             return (String)var3;
  203.          }
  204.       }
  205.  
  206.       return null;
  207.    }
  208.  
  209.    public String getHeaderField(String var1) {
  210.       if (!this.connected) {
  211.          try {
  212.             this.connect();
  213.          } catch (Exception var3) {
  214.             return null;
  215.          }
  216.       }
  217.  
  218.       this.waitForHeaderLoaded();
  219.       return (String)this.field_0.header_fields.get(var1.toLowerCase());
  220.    }
  221.  
  222.    public String getRequestProperty(String var1) {
  223.       return (String)this.field_1.req_props.get(var1);
  224.    }
  225.  
  226.    public void setRequestProperty(String var1, String var2) {
  227.       if (var1.compareToIgnoreCase("Content-length") != 0) {
  228.          this.field_1.req_props.put(var1, var2);
  229.       }
  230.  
  231.    }
  232.  
  233.    public void disconnect() {
  234.    }
  235.  
  236.    public boolean usingProxy() {
  237.       return false;
  238.    }
  239.  
  240.    public int getResponseCode() throws IOException {
  241.       if (!this.connected) {
  242.          this.connect();
  243.       }
  244.  
  245.       try {
  246.          synchronized(this.field_0) {
  247.             if (!this.field_0.isHeaderLoaded()) {
  248.                this.field_0.wait();
  249.                this.responseCode = this.field_0.getResponse();
  250.             }
  251.          }
  252.       } catch (InterruptedException var4) {
  253.          Thread.currentThread().interrupt();
  254.       }
  255.  
  256.       return this.responseCode;
  257.    }
  258.  
  259.    protected void finalize() throws Throwable {
  260.       if (this.istream_id != -1) {
  261.          OperaInputStream.removeStream(this.istream_id);
  262.       }
  263.  
  264.       super.finalize();
  265.    }
  266.  
  267.    protected void waitForHeaderLoaded() {
  268.       try {
  269.          synchronized(this.field_0) {
  270.             if (!this.field_0.isHeaderLoaded()) {
  271.                this.field_0.wait();
  272.             }
  273.          }
  274.       } catch (InterruptedException var4) {
  275.          Thread.currentThread().interrupt();
  276.       }
  277.  
  278.    }
  279. }
  280.