home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / ie4 / IE4 / JAVI386.CAB / classr.exe / sun / net / www / URLConnection.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-31  |  2.5 KB  |  121 lines

  1. package sun.net.www;
  2.  
  3. import java.io.IOException;
  4. import java.net.URL;
  5.  
  6. public abstract class URLConnection extends java.net.URLConnection {
  7.    private String contentType;
  8.    private int contentLength = -1;
  9.    private MessageHeader properties;
  10.  
  11.    public URLConnection(URL var1) {
  12.       super(var1);
  13.    }
  14.  
  15.    public MessageHeader getProperties() {
  16.       return this.properties;
  17.    }
  18.  
  19.    public void setProperties(MessageHeader var1) {
  20.       this.properties = var1;
  21.    }
  22.  
  23.    public String getHeaderField(String var1) {
  24.       try {
  25.          ((java.net.URLConnection)this).getInputStream();
  26.       } catch (Exception var3) {
  27.          return null;
  28.       }
  29.  
  30.       MessageHeader var2 = this.properties;
  31.       return var2 == null ? null : var2.findValue(var1);
  32.    }
  33.  
  34.    public String GetHeaderFieldKey(int var1) {
  35.       try {
  36.          ((java.net.URLConnection)this).getInputStream();
  37.       } catch (Exception var3) {
  38.          return null;
  39.       }
  40.  
  41.       MessageHeader var2 = this.properties;
  42.       return var2 == null ? null : var2.getKey(var1);
  43.    }
  44.  
  45.    public String GetHeaderField(int var1) {
  46.       try {
  47.          ((java.net.URLConnection)this).getInputStream();
  48.       } catch (Exception var3) {
  49.          return null;
  50.       }
  51.  
  52.       MessageHeader var2 = this.properties;
  53.       return var2 == null ? null : var2.getValue(var1);
  54.    }
  55.  
  56.    public String getContentType() {
  57.       if (this.contentType == null) {
  58.          this.contentType = this.getHeaderField("content-type");
  59.       }
  60.  
  61.       if (this.contentType == null) {
  62.          String var1 = null;
  63.  
  64.          try {
  65.             var1 = java.net.URLConnection.guessContentTypeFromStream(((java.net.URLConnection)this).getInputStream());
  66.          } catch (IOException var3) {
  67.          }
  68.  
  69.          String var2 = this.properties.findValue("content-encoding");
  70.          if (var1 == null) {
  71.             var1 = this.properties.findValue("content-type");
  72.             if (var1 == null) {
  73.                if (super.url.getFile().endsWith("/")) {
  74.                   var1 = "text/html";
  75.                } else {
  76.                   var1 = java.net.URLConnection.guessContentTypeFromName(super.url.getFile());
  77.                }
  78.             }
  79.          }
  80.  
  81.          if (var1 == null || var2 != null && !var2.equalsIgnoreCase("7bit") && !var2.equalsIgnoreCase("8bit") && !var2.equalsIgnoreCase("binary")) {
  82.             var1 = "content/unknown";
  83.          }
  84.  
  85.          this.contentType = var1;
  86.       }
  87.  
  88.       return this.contentType;
  89.    }
  90.  
  91.    public void setContentType(String var1) {
  92.       this.contentType = var1;
  93.    }
  94.  
  95.    public int getContentLength() {
  96.       int var1 = this.contentLength;
  97.       if (var1 < 0) {
  98.          try {
  99.             ((java.net.URLConnection)this).getInputStream();
  100.             var1 = Integer.parseInt(this.properties.findValue("content-length"));
  101.             this.contentLength = var1;
  102.          } catch (Exception var2) {
  103.          }
  104.       }
  105.  
  106.       return var1;
  107.    }
  108.  
  109.    protected void setContentLength(int var1) {
  110.       this.contentLength = var1;
  111.    }
  112.  
  113.    public boolean canCache() {
  114.       return super.url.getFile().indexOf(63) < 0;
  115.    }
  116.  
  117.    public void close() {
  118.       super.url = null;
  119.    }
  120. }
  121.