home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / sun / net / www / protocol / ftp / FtpURLConnection.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  3.8 KB  |  138 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.SocketPermission;
  9. import java.net.URL;
  10. import java.net.UnknownHostException;
  11. import java.security.AccessController;
  12. import java.security.Permission;
  13. import sun.net.ProgressData;
  14. import sun.net.ProgressEntry;
  15. import sun.net.ftp.FtpClient;
  16. import sun.net.www.MessageHeader;
  17. import sun.net.www.MeteredStream;
  18. import sun.net.www.ParseUtil;
  19. import sun.net.www.URLConnection;
  20. import sun.security.action.GetPropertyAction;
  21.  
  22. public class FtpURLConnection extends URLConnection {
  23.    // $FF: renamed from: is java.io.InputStream
  24.    InputStream field_0 = null;
  25.    FtpClient ftp = null;
  26.    Permission permission;
  27.    String password;
  28.    String user;
  29.    String host;
  30.  
  31.    public FtpURLConnection(URL var1) {
  32.       super(var1);
  33.       this.host = var1.getHost();
  34.       String var2 = var1.getUserInfo();
  35.       if (var2 != null) {
  36.          int var3 = var2.indexOf(58);
  37.          this.user = var2.substring(0, var3++);
  38.          this.password = var2.substring(var3);
  39.       }
  40.  
  41.    }
  42.  
  43.    public synchronized void connect() throws IOException {
  44.       if (!super.connected) {
  45.          try {
  46.             this.ftp = new FtpClient(this.host);
  47.          } catch (UnknownHostException var2) {
  48.             throw var2;
  49.          }
  50.  
  51.          if (this.user == null || this.password == null) {
  52.             this.user = "anonymous";
  53.             String var1 = (String)AccessController.doPrivileged(new GetPropertyAction("java.version"));
  54.             this.password = (String)AccessController.doPrivileged(new GetPropertyAction("ftp.protocol.user", "Java" + var1 + "@"));
  55.          }
  56.  
  57.          this.ftp.login(this.user, this.password);
  58.       }
  59.    }
  60.  
  61.    public InputStream getInputStream() throws IOException {
  62.       if (!super.connected) {
  63.          this.connect();
  64.       }
  65.  
  66.       if (this.field_0 != null) {
  67.          return this.field_0;
  68.       } else {
  69.          MessageHeader var1 = new MessageHeader();
  70.          Object var2 = null;
  71.  
  72.          try {
  73.             this.ftp.binary();
  74.             String var10 = ParseUtil.decode(super.url.getPath());
  75.             this.field_0 = this.ftp.get(var10);
  76.  
  77.             try {
  78.                String var3 = this.ftp.getResponseString();
  79.                int var12;
  80.                if ((var12 = var3.indexOf(" bytes)")) != -1) {
  81.                   int var5 = var12;
  82.  
  83.                   char var6;
  84.                   do {
  85.                      --var5;
  86.                   } while(var5 >= 0 && (var6 = var3.charAt(var5)) >= '0' && var6 <= '9');
  87.  
  88.                   var5 = Integer.parseInt(var3.substring(var5 + 1, var12));
  89.                   var1.add("content-length", "" + var5);
  90.                   if (var5 > 0) {
  91.                      ProgressEntry var7 = new ProgressEntry(var10, (String)null);
  92.                      var7.update(0, var5);
  93.                      ProgressData.pdata.register(var7);
  94.                      this.field_0 = new MeteredStream(this.field_0, var7);
  95.                   }
  96.                }
  97.             } catch (Exception var8) {
  98.                ((Throwable)var8).printStackTrace();
  99.             }
  100.  
  101.             String var11 = java.net.URLConnection.guessContentTypeFromName(var10);
  102.             if (var11 == null && this.field_0.markSupported()) {
  103.                var11 = java.net.URLConnection.guessContentTypeFromStream(this.field_0);
  104.             }
  105.  
  106.             if (var11 != null) {
  107.                var1.add("content-type", var11);
  108.             }
  109.          } catch (FileNotFoundException var9) {
  110.             this.ftp.cd(super.url.getFile());
  111.             this.ftp.ascii();
  112.             PipedOutputStream var4 = new PipedOutputStream();
  113.             this.field_0 = new PipedInputStream(var4);
  114.             (new FtpDirectoryThread(this, this.ftp, super.url, this.host, this.ftp.list(), var4)).start();
  115.             var1.add("content-type", "text/html");
  116.          }
  117.  
  118.          ((URLConnection)this).setProperties(var1);
  119.          return this.field_0;
  120.       }
  121.    }
  122.  
  123.    String guessContentTypeFromFilename(String var1) {
  124.       return java.net.URLConnection.guessContentTypeFromName(var1);
  125.    }
  126.  
  127.    public Permission getPermission() {
  128.       if (this.permission == null) {
  129.          int var1 = super.url.getPort();
  130.          var1 = var1 < 0 ? 21 : var1;
  131.          String var2 = this.host + ":" + var1;
  132.          this.permission = new SocketPermission(var2, "connect");
  133.       }
  134.  
  135.       return this.permission;
  136.    }
  137. }
  138.