Author: sebb
Date: Fri Mar 24 15:56:14 2017
New Revision: 1788489

URL: http://svn.apache.org/viewvc?rev=1788489&view=rev
Log:
NET-632 FTPHTTPClient - support for encoding other than UTF-8

This fixes #1

Modified:
    commons/proper/net/trunk/src/changes/changes.xml
    
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1788489&r1=1788488&r2=1788489&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/net/trunk/src/changes/changes.xml [utf-8] Fri Mar 24 
15:56:14 2017
@@ -71,6 +71,9 @@ This is mainly a bug-fix release. See fu
  However it is not source compatible with releases before 3.4, as some methods 
were added to the interface NtpV3Packet in 3.4
         
 ">
+            <action issue="NET-632" type="update" dev="sebb" 
due-to="prakapenka">
+            FTPHTTPClient - support for encoding other than UTF-8
+            </action>
             <action issue="NET-631" type="fix" dev="sebb">
             Bug in MVSFTPEntryParser.parseUnixList (FindBugs)
             </action>

Modified: 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
URL: 
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java?rev=1788489&r1=1788488&r2=1788489&view=diff
==============================================================================
--- 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
 (original)
+++ 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
 Fri Mar 24 15:56:14 2017
@@ -27,6 +27,7 @@ import java.io.UnsupportedEncodingExcept
 import java.net.Inet6Address;
 import java.net.Socket;
 import java.net.SocketException;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -42,26 +43,67 @@ public class FTPHTTPClient extends FTPCl
     private final int proxyPort;
     private final String proxyUsername;
     private final String proxyPassword;
+    private final Charset charset;
 
     private static final byte[] CRLF={'\r', '\n'};
     private final Base64 base64 = new Base64();
 
     private String tunnelHost; // Save the host when setting up a tunnel 
(needed for EPSV)
 
-    public FTPHTTPClient(String proxyHost, int proxyPort, String proxyUser, 
String proxyPass) {
+    /**
+     * Create an instance with the specified encoding
+     *
+     * @param proxyHost the hostname to use
+     * @param proxyPort the port to use
+     * @param proxyUser the user name for the proxy
+     * @param proxyPass the password for the proxy
+     * @param encoding the encoding to use
+     */
+    public FTPHTTPClient(String proxyHost, int proxyPort, String proxyUser, 
String proxyPass, Charset encoding) {
         this.proxyHost = proxyHost;
         this.proxyPort = proxyPort;
         this.proxyUsername = proxyUser;
         this.proxyPassword = proxyPass;
         this.tunnelHost = null;
+        this.charset = null;
+    }
+
+    /**
+     * Create an instance using the UTF-8 encoding
+     *
+     * @param proxyHost the hostname to use
+     * @param proxyPort the port to use
+     * @param proxyUser the user name for the proxy
+     * @param proxyPass the password for the proxy
+     */
+    public FTPHTTPClient(String proxyHost, int proxyPort, String proxyUser, 
String proxyPass) {
+        this(proxyHost, proxyPort, proxyUser, proxyPass, 
Charset.forName("UTF-8"));
     }
 
+    /**
+     * Create an instance using the UTF-8 encoding, with no proxy credentials.
+     *
+     * @param proxyHost the hostname to use
+     * @param proxyPort the port to use
+     */
     public FTPHTTPClient(String proxyHost, int proxyPort) {
         this(proxyHost, proxyPort, null, null);
     }
 
 
     /**
+     * Create an instance using the specified encoding, with no proxy 
credentials.
+     *
+     * @param proxyHost the hostname to use
+     * @param proxyPort the port to use
+     * @param encoding the encoding to use
+     */
+    public FTPHTTPClient(String proxyHost, int proxyPort, Charset encoding) {
+        this(proxyHost, proxyPort, null, null, encoding);
+    }
+
+
+    /**
      * {@inheritDoc}
      *
      * @throws IllegalStateException if connection mode is not passive
@@ -150,16 +192,16 @@ public class FTPHTTPClient extends FTPCl
         final String hostString = "Host: " + host + ":" + port;
 
         this.tunnelHost = host;
-        output.write(connectString.getBytes("UTF-8")); // TODO what is the 
correct encoding?
+        output.write(connectString.getBytes(charset));
         output.write(CRLF);
-        output.write(hostString.getBytes("UTF-8"));
+        output.write(hostString.getBytes(charset));
         output.write(CRLF);
 
         if (proxyUsername != null && proxyPassword != null) {
             final String auth = proxyUsername + ":" + proxyPassword;
             final String header = "Proxy-Authorization: Basic "
-                + base64.encodeToString(auth.getBytes("UTF-8"));
-            output.write(header.getBytes("UTF-8"));
+                + base64.encodeToString(auth.getBytes(charset));
+            output.write(header.getBytes(charset));
         }
         output.write(CRLF);
 


Reply via email to