home *** CD-ROM | disk | FTP | other *** search
- package sun.net.www.protocol.ftp;
-
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.PipedInputStream;
- import java.io.PipedOutputStream;
- import java.net.SocketPermission;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.security.AccessController;
- import java.security.Permission;
- import sun.net.ProgressData;
- import sun.net.ProgressEntry;
- import sun.net.ftp.FtpClient;
- import sun.net.www.MessageHeader;
- import sun.net.www.MeteredStream;
- import sun.net.www.ParseUtil;
- import sun.net.www.URLConnection;
- import sun.security.action.GetPropertyAction;
-
- public class FtpURLConnection extends URLConnection {
- // $FF: renamed from: is java.io.InputStream
- InputStream field_0 = null;
- FtpClient ftp = null;
- Permission permission;
- String password;
- String user;
- String host;
-
- public FtpURLConnection(URL var1) {
- super(var1);
- this.host = var1.getHost();
- String var2 = var1.getUserInfo();
- if (var2 != null) {
- int var3 = var2.indexOf(58);
- this.user = var2.substring(0, var3++);
- this.password = var2.substring(var3);
- }
-
- }
-
- public synchronized void connect() throws IOException {
- if (!super.connected) {
- try {
- this.ftp = new FtpClient(this.host);
- } catch (UnknownHostException var2) {
- throw var2;
- }
-
- if (this.user == null || this.password == null) {
- this.user = "anonymous";
- String var1 = (String)AccessController.doPrivileged(new GetPropertyAction("java.version"));
- this.password = (String)AccessController.doPrivileged(new GetPropertyAction("ftp.protocol.user", "Java" + var1 + "@"));
- }
-
- this.ftp.login(this.user, this.password);
- }
- }
-
- public InputStream getInputStream() throws IOException {
- if (!super.connected) {
- this.connect();
- }
-
- if (this.field_0 != null) {
- return this.field_0;
- } else {
- MessageHeader var1 = new MessageHeader();
- Object var2 = null;
-
- try {
- this.ftp.binary();
- String var10 = ParseUtil.decode(super.url.getPath());
- this.field_0 = this.ftp.get(var10);
-
- try {
- String var3 = this.ftp.getResponseString();
- int var12;
- if ((var12 = var3.indexOf(" bytes)")) != -1) {
- int var5 = var12;
-
- char var6;
- do {
- --var5;
- } while(var5 >= 0 && (var6 = var3.charAt(var5)) >= '0' && var6 <= '9');
-
- var5 = Integer.parseInt(var3.substring(var5 + 1, var12));
- var1.add("content-length", "" + var5);
- if (var5 > 0) {
- ProgressEntry var7 = new ProgressEntry(var10, (String)null);
- var7.update(0, var5);
- ProgressData.pdata.register(var7);
- this.field_0 = new MeteredStream(this.field_0, var7);
- }
- }
- } catch (Exception var8) {
- ((Throwable)var8).printStackTrace();
- }
-
- String var11 = java.net.URLConnection.guessContentTypeFromName(var10);
- if (var11 == null && this.field_0.markSupported()) {
- var11 = java.net.URLConnection.guessContentTypeFromStream(this.field_0);
- }
-
- if (var11 != null) {
- var1.add("content-type", var11);
- }
- } catch (FileNotFoundException var9) {
- this.ftp.cd(super.url.getFile());
- this.ftp.ascii();
- PipedOutputStream var4 = new PipedOutputStream();
- this.field_0 = new PipedInputStream(var4);
- (new FtpDirectoryThread(this, this.ftp, super.url, this.host, this.ftp.list(), var4)).start();
- var1.add("content-type", "text/html");
- }
-
- ((URLConnection)this).setProperties(var1);
- return this.field_0;
- }
- }
-
- String guessContentTypeFromFilename(String var1) {
- return java.net.URLConnection.guessContentTypeFromName(var1);
- }
-
- public Permission getPermission() {
- if (this.permission == null) {
- int var1 = super.url.getPort();
- var1 = var1 < 0 ? 21 : var1;
- String var2 = this.host + ":" + var1;
- this.permission = new SocketPermission(var2, "connect");
- }
-
- return this.permission;
- }
- }
-