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 / protocol / ftp / FtpURLConnection.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-08  |  3.4 KB  |  102 lines

  1. package sun.net.www.protocol.ftp;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.PipedInputStream;
  7. import java.io.PipedOutputStream;
  8. import java.net.URL;
  9. import java.net.UnknownHostException;
  10. import sun.net.ProgressData;
  11. import sun.net.ProgressEntry;
  12. import sun.net.ftp.FtpClient;
  13. import sun.net.www.MessageHeader;
  14. import sun.net.www.MeteredStream;
  15. import sun.net.www.URLConnection;
  16.  
  17. public class FtpURLConnection extends URLConnection {
  18.    // $FF: renamed from: is java.io.InputStream
  19.    InputStream field_0;
  20.    FtpClient ftp;
  21.  
  22.    public FtpURLConnection(URL var1) {
  23.       super(var1);
  24.    }
  25.  
  26.    public synchronized void connect() throws IOException {
  27.       if (!super.connected) {
  28.          try {
  29.             this.ftp = new FtpClient(super.url.getHost());
  30.          } catch (UnknownHostException var2) {
  31.             throw var2;
  32.          }
  33.  
  34.          this.ftp.login("anonymous", System.getProperty("ftp.protocol.user", "Java" + System.getProperty("java.version") + "@"));
  35.       }
  36.    }
  37.  
  38.    public InputStream getInputStream() throws IOException {
  39.       if (!super.connected) {
  40.          this.connect();
  41.       }
  42.  
  43.       if (this.field_0 != null) {
  44.          return this.field_0;
  45.       } else {
  46.          MessageHeader var1 = new MessageHeader();
  47.  
  48.          try {
  49.             this.ftp.binary();
  50.             this.field_0 = this.ftp.get(super.url.getFile());
  51.  
  52.             try {
  53.                String var9 = this.ftp.getResponseString();
  54.                int var3;
  55.                if ((var3 = var9.indexOf(" bytes)")) != -1) {
  56.                   int var4 = var3;
  57.  
  58.                   char var5;
  59.                   do {
  60.                      --var4;
  61.                   } while(var4 >= 0 && (var5 = var9.charAt(var4)) >= '0' && var5 <= '9');
  62.  
  63.                   var4 = Integer.parseInt(var9.substring(var4 + 1, var3));
  64.                   var1.add("content-length", String.valueOf(var4));
  65.                   if (var4 > 0) {
  66.                      ProgressEntry var6 = new ProgressEntry(super.url.getFile(), (String)null);
  67.                      var6.update(0, var4);
  68.                      ProgressData.pdata.register(var6);
  69.                      this.field_0 = new MeteredStream(this.field_0, var6);
  70.                   }
  71.                }
  72.             } catch (Exception var7) {
  73.                ((Throwable)var7).printStackTrace();
  74.             }
  75.  
  76.             String var10 = java.net.URLConnection.guessContentTypeFromName(super.url.getFile());
  77.             if (var10 == null && this.field_0.markSupported()) {
  78.                var10 = java.net.URLConnection.guessContentTypeFromStream(this.field_0);
  79.             }
  80.  
  81.             if (var10 != null) {
  82.                var1.add("content-type", var10);
  83.             }
  84.          } catch (FileNotFoundException var8) {
  85.             this.ftp.cd(super.url.getFile());
  86.             this.ftp.ascii();
  87.             PipedOutputStream var2 = new PipedOutputStream();
  88.             this.field_0 = new PipedInputStream(var2);
  89.             (new FtpDirectoryThread(this, this.ftp, super.url, this.ftp.list(), var2)).start();
  90.             var1.add("content-type", "text/html");
  91.          }
  92.  
  93.          ((URLConnection)this).setProperties(var1);
  94.          return this.field_0;
  95.       }
  96.    }
  97.  
  98.    String guessContentTypeFromFilename(String var1) {
  99.       return java.net.URLConnection.guessContentTypeFromName(var1);
  100.    }
  101. }
  102.