commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r922826 - /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
Date Sun, 14 Mar 2010 12:26:32 GMT
Author: sebb
Date: Sun Mar 14 12:26:32 2010
New Revision: 922826

URL: http://svn.apache.org/viewvc?rev=922826&view=rev
Log:
Tab police

Modified:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java?rev=922826&r1=922825&r2=922826&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
Sun Mar 14 12:26:32 2010
@@ -32,114 +32,114 @@ import org.apache.commons.net.util.Base6
 
 /**
  * Experimental attempt at FTP client that tunnels over an HTTP proxy connection.
- * 
+ *
  * @author rory
  *
  */
 public class FTPHTTPClient extends FTPClient {
-	private final String proxyHost;
-	private int proxyPort;
-	private final String proxyUsername;
-	private final String proxyPassword;
-	private String host;
-	private int port;
-
-	private final byte[] CRLF;
-	private final Base64 base64 = new Base64();
-
-	public FTPHTTPClient(String proxyHost, int proxyPort, String proxyUser, String proxyPass)
{
-		this.proxyHost = proxyHost;
-		this.proxyPort = proxyPort;
-		this.proxyUsername = proxyUser;
-		this.proxyPassword = proxyPass;
-
-		try {
-			CRLF = "\r\n".getBytes(getControlEncoding());
-		} catch (UnsupportedEncodingException e) {
-			throw new RuntimeException(e);
-		}
-	}
-
-	public FTPHTTPClient(String proxyHost, int proxyPort) {
-		this(proxyHost, proxyPort, null, null);
-	}
-
-	
-	@Override
-	protected Socket _openDataConnection_(int command, String arg)
-	throws IOException {
-		Socket socket = new Socket(host, port);
-		InputStream is = socket.getInputStream();
-		OutputStream os = socket.getOutputStream();
-
-		tunnelHandshake(host, port, is, os);
-
-		return socket;
-	}
-
-	public void connect(String host, int port) throws SocketException,
-	IOException {
-		this.host = host;
-		this.port = port;
-
-		_socket_ = new Socket(proxyHost, proxyPort);
-		_input_ = _socket_.getInputStream();
-		_output_ = _socket_.getOutputStream();
-		try {
-			tunnelHandshake(host, port, _input_, _output_);
-		} 
-		catch (Exception e) {
-			throw new IOException(e);
-		}
-	}
-
-	private void tunnelHandshake(String host, int port, InputStream input, OutputStream output)
throws IOException,
-	UnsupportedEncodingException {
-		final String connectString = "CONNECT "  + host + ":" + port  + " HTTP/1.1";
-
-		_output_.write(connectString.getBytes(getControlEncoding()));
-		_output_.write(CRLF);
-
-		if (proxyUsername != null && proxyPassword != null) {
-			final String header = "Proxy-Authorization: Basic "
-				+ base64.encode(proxyUsername + ":" + proxyPassword) + "\r\n";
-			_output_.write(header.getBytes("UTF-8"));
-			_output_.write(CRLF);
-			
-			List<String> response = new ArrayList<String>();
-			BufferedReader reader = new BufferedReader(
-					new InputStreamReader(_input_));
-
-			for (String line = reader.readLine(); line != null
-			&& line.length() > 0; line = reader.readLine()) {
-				response.add(line);
-			}
-			
-			int size = response.size();
-			if (size == 0) {
-				throw new IOException("No response from proxy");
-			}
-
-			String code = null;
-			String resp = (String) response.get(0);
-			if (resp.startsWith("HTTP/") && resp.length() >= 12) {
-				code = resp.substring(9, 12);
-			} else {
-				throw new IOException("Invalid response from proxy: " + resp);
-			}
-
-			if (!"200".equals(code)) {
-				StringBuilder msg = new StringBuilder();
-				msg.append("HTTPTunnelConnector: connection failed\r\n");
-				msg.append("Response received from the proxy:\r\n");
-				for (String line : response) {
-					msg.append(line);
-					msg.append("\r\n");
-				}
-				throw new IOException(msg.toString());
-			}
-		}
-	}
+    private final String proxyHost;
+    private int proxyPort;
+    private final String proxyUsername;
+    private final String proxyPassword;
+    private String host;
+    private int port;
+
+    private final byte[] CRLF;
+    private final Base64 base64 = new Base64();
+
+    public FTPHTTPClient(String proxyHost, int proxyPort, String proxyUser, String proxyPass)
{
+        this.proxyHost = proxyHost;
+        this.proxyPort = proxyPort;
+        this.proxyUsername = proxyUser;
+        this.proxyPassword = proxyPass;
+
+        try {
+            CRLF = "\r\n".getBytes(getControlEncoding());
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public FTPHTTPClient(String proxyHost, int proxyPort) {
+        this(proxyHost, proxyPort, null, null);
+    }
+
+
+    @Override
+    protected Socket _openDataConnection_(int command, String arg)
+    throws IOException {
+        Socket socket = new Socket(host, port);
+        InputStream is = socket.getInputStream();
+        OutputStream os = socket.getOutputStream();
+
+        tunnelHandshake(host, port, is, os);
+
+        return socket;
+    }
+
+    public void connect(String host, int port) throws SocketException,
+    IOException {
+        this.host = host;
+        this.port = port;
+
+        _socket_ = new Socket(proxyHost, proxyPort);
+        _input_ = _socket_.getInputStream();
+        _output_ = _socket_.getOutputStream();
+        try {
+            tunnelHandshake(host, port, _input_, _output_);
+        }
+        catch (Exception e) {
+            throw new IOException(e);
+        }
+    }
+
+    private void tunnelHandshake(String host, int port, InputStream input, OutputStream output)
throws IOException,
+    UnsupportedEncodingException {
+        final String connectString = "CONNECT "  + host + ":" + port  + " HTTP/1.1";
+
+        _output_.write(connectString.getBytes(getControlEncoding()));
+        _output_.write(CRLF);
+
+        if (proxyUsername != null && proxyPassword != null) {
+            final String header = "Proxy-Authorization: Basic "
+                + base64.encode(proxyUsername + ":" + proxyPassword) + "\r\n";
+            _output_.write(header.getBytes("UTF-8"));
+            _output_.write(CRLF);
+
+            List<String> response = new ArrayList<String>();
+            BufferedReader reader = new BufferedReader(
+                    new InputStreamReader(_input_));
+
+            for (String line = reader.readLine(); line != null
+            && line.length() > 0; line = reader.readLine()) {
+                response.add(line);
+            }
+
+            int size = response.size();
+            if (size == 0) {
+                throw new IOException("No response from proxy");
+            }
+
+            String code = null;
+            String resp = (String) response.get(0);
+            if (resp.startsWith("HTTP/") && resp.length() >= 12) {
+                code = resp.substring(9, 12);
+            } else {
+                throw new IOException("Invalid response from proxy: " + resp);
+            }
+
+            if (!"200".equals(code)) {
+                StringBuilder msg = new StringBuilder();
+                msg.append("HTTPTunnelConnector: connection failed\r\n");
+                msg.append("Response received from the proxy:\r\n");
+                for (String line : response) {
+                    msg.append(line);
+                    msg.append("\r\n");
+                }
+                throw new IOException(msg.toString());
+            }
+        }
+    }
 }
 
 



Mime
View raw message