home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / sun / net / www / URLConnection.class (.txt) < prev   
Encoding:
Java Class File  |  1997-07-08  |  2.8 KB  |  133 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.    protected MessageHeader properties = new MessageHeader();
  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 void setRequestProperty(String var1, String var2) {
  24.       if (super.connected) {
  25.          throw new IllegalAccessError("Already connected");
  26.       } else {
  27.          this.properties.add(var1, var2);
  28.       }
  29.    }
  30.  
  31.    public String getHeaderField(String var1) {
  32.       try {
  33.          ((java.net.URLConnection)this).getInputStream();
  34.       } catch (Exception var2) {
  35.          return null;
  36.       }
  37.  
  38.       return this.properties == null ? null : this.properties.findValue(var1);
  39.    }
  40.  
  41.    public String getHeaderFieldKey(int var1) {
  42.       try {
  43.          ((java.net.URLConnection)this).getInputStream();
  44.       } catch (Exception var3) {
  45.          return null;
  46.       }
  47.  
  48.       MessageHeader var2 = this.properties;
  49.       return var2 == null ? null : var2.getKey(var1);
  50.    }
  51.  
  52.    public String getHeaderField(int var1) {
  53.       try {
  54.          ((java.net.URLConnection)this).getInputStream();
  55.       } catch (Exception var3) {
  56.          return null;
  57.       }
  58.  
  59.       MessageHeader var2 = this.properties;
  60.       return var2 == null ? null : var2.getValue(var1);
  61.    }
  62.  
  63.    public String getContentType() {
  64.       if (this.contentType == null) {
  65.          this.contentType = this.getHeaderField("content-type");
  66.       }
  67.  
  68.       if (this.contentType == null) {
  69.          String var1 = null;
  70.  
  71.          try {
  72.             var1 = java.net.URLConnection.guessContentTypeFromStream(((java.net.URLConnection)this).getInputStream());
  73.          } catch (IOException var3) {
  74.          }
  75.  
  76.          String var2 = this.properties.findValue("content-encoding");
  77.          if (var1 == null) {
  78.             var1 = this.properties.findValue("content-type");
  79.             if (var1 == null) {
  80.                if (super.url.getFile().endsWith("/")) {
  81.                   var1 = "text/html";
  82.                } else {
  83.                   var1 = java.net.URLConnection.guessContentTypeFromName(super.url.getFile());
  84.                }
  85.             }
  86.          }
  87.  
  88.          if (var1 == null || var2 != null && !var2.equalsIgnoreCase("7bit") && !var2.equalsIgnoreCase("8bit") && !var2.equalsIgnoreCase("binary")) {
  89.             var1 = "content/unknown";
  90.          }
  91.  
  92.          this.contentType = var1;
  93.       }
  94.  
  95.       return this.contentType;
  96.    }
  97.  
  98.    public void setContentType(String var1) {
  99.       this.contentType = var1;
  100.    }
  101.  
  102.    public int getContentLength() {
  103.       try {
  104.          ((java.net.URLConnection)this).getInputStream();
  105.       } catch (Exception var3) {
  106.          return -1;
  107.       }
  108.  
  109.       int var1 = this.contentLength;
  110.       if (var1 < 0) {
  111.          try {
  112.             var1 = Integer.parseInt(this.properties.findValue("content-length"));
  113.             this.contentLength = var1;
  114.          } catch (Exception var2) {
  115.          }
  116.       }
  117.  
  118.       return var1;
  119.    }
  120.  
  121.    protected void setContentLength(int var1) {
  122.       this.contentLength = var1;
  123.    }
  124.  
  125.    public boolean canCache() {
  126.       return super.url.getFile().indexOf(63) < 0;
  127.    }
  128.  
  129.    public void close() {
  130.       super.url = null;
  131.    }
  132. }
  133.