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

  1. package sun.net.www.protocol.file;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.net.URL;
  9. import sun.net.www.MessageHeader;
  10. import sun.net.www.URLConnection;
  11.  
  12. public class FileURLConnection extends URLConnection {
  13.    static String installDirectory;
  14.    // $FF: renamed from: is java.io.InputStream
  15.    InputStream field_0;
  16.  
  17.    FileURLConnection(URL var1) {
  18.       super(var1);
  19.    }
  20.  
  21.    String toFileForm(String var1) {
  22.       return var1.startsWith("/\\\\") ? "/\\\\" + var1.substring(3).replace('/', File.separatorChar) : var1.replace('/', File.separatorChar);
  23.    }
  24.  
  25.    public int getContentLength() {
  26.       File var1 = new File(this.toFileForm(super.url.getFile()));
  27.       return (int)var1.length();
  28.    }
  29.  
  30.    public void connect() throws IOException {
  31.       String var1 = super.url.getFile();
  32.       MessageHeader var2 = new MessageHeader();
  33.       String var3;
  34.       if (var1.endsWith("/")) {
  35.          var3 = "text/html";
  36.          var1 = var1 + "index.html";
  37.       } else {
  38.          var3 = java.net.URLConnection.guessContentTypeFromName(var1);
  39.       }
  40.  
  41.       if (var3 != null) {
  42.          var2.add("content-type", var3);
  43.       }
  44.  
  45.       var1 = this.toFileForm(var1);
  46.       String var4 = super.url.getHost();
  47.       if (var4.equals("~")) {
  48.          if (installDirectory == null) {
  49.             installDirectory = System.getProperty("hotjava.home");
  50.             if (installDirectory == null) {
  51.                installDirectory = "/usr/local/hotjava".replace('/', File.separatorChar);
  52.             }
  53.          }
  54.  
  55.          var1 = installDirectory + var1;
  56.       }
  57.  
  58.       ((URLConnection)this).setProperties(var2);
  59.       this.field_0 = new BufferedInputStream(new FileInputStream(var1));
  60.       super.connected = true;
  61.    }
  62.  
  63.    public synchronized InputStream getInputStream() throws IOException {
  64.       if (!super.connected) {
  65.          this.connect();
  66.       }
  67.  
  68.       return this.field_0;
  69.    }
  70. }
  71.