You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by df...@apache.org on 2004/08/08 21:50:48 UTC
cvs commit: jakarta-commons/net/src/java/org/apache/commons/net/ftp FTP.java
dfs 2004/08/08 12:50:48
Modified: net/src/java/org/apache/commons/net/ftp FTP.java
Log:
Added a means to set the character encoding used by the control
connection. As reported by "Ash, Michael L" <Michael.Ash at ca.com>,
some FTP servers require other encodings.
Renamed __DEFAULT_ENCODING to DEFAULT_CONTROL_ENCODING and made it
public. Added a _controlEncoding member variable and public setter
and getter methods. Initialized control connection in _connectAction_
with the value returned by getControlEncoding().
Revision Changes Path
1.15 +42 -3 jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTP.java
Index: FTP.java
===================================================================
RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTP.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- FTP.java 29 Jun 2004 04:54:30 -0000 1.14
+++ FTP.java 8 Aug 2004 19:50:48 -0000 1.15
@@ -207,7 +207,14 @@
// We have to ensure that the protocol communication is in ASCII
// but we use ISO-8859-1 just in case 8-bit characters cross
// the wire.
- private static final String __DEFAULT_ENCODING = "ISO-8859-1";
+ /**
+ * The default character encoding used for communicating over an
+ * FTP control connection. The default encoding is an
+ * ASCII-compatible encoding. Some FTP servers expect other
+ * encodings. You can change the encoding used by an FTP instance
+ * with {@link setControlEncoding}.
+ */
+ public static final String DEFAULT_CONTROL_ENCODING = "ISO-8859-1";
private static final String __modes = "ABILNTCFRPSBC";
private StringBuffer __commandBuffer;
@@ -218,6 +225,7 @@
Vector _replyLines;
boolean _newReplyString;
String _replyString;
+ String _controlEncoding;
/***
* A ProtocolCommandSupport object used to manage the registering of
@@ -238,6 +246,7 @@
_newReplyString = false;
_replyString = null;
_commandSupport_ = new ProtocolCommandSupport(this);
+ _controlEncoding = DEFAULT_CONTROL_ENCODING;
}
private void __getReply() throws IOException
@@ -314,10 +323,10 @@
super._connectAction_();
_controlInput =
new BufferedReader(new InputStreamReader(getInputStream(),
- __DEFAULT_ENCODING));
+ getControlEncoding()));
_controlOutput =
new BufferedWriter(new OutputStreamWriter(getOutputStream(),
- __DEFAULT_ENCODING));
+ getControlEncoding()));
__getReply();
// If we received code 120, we have to fetch completion reply.
if (FTPReply.isPositivePreliminary(_replyCode))
@@ -325,6 +334,28 @@
}
+ /**
+ * Sets the character encoding used by the FTP control connection.
+ * Some FTP servers require that commands be issued in a non-ASCII
+ * encoding like UTF-8 so that filenames with multi-byte character
+ * representations (e.g, Big 8) can be specified.
+ *
+ * @param encoding The new character encoding for the control connection.
+ */
+ public void setControlEncoding(String encoding) {
+ _controlEncoding = encoding;
+ }
+
+
+ /**
+ * @return The character encoding used to communicate over the
+ * control connection.
+ */
+ public String getControlEncoding() {
+ return _controlEncoding;
+ }
+
+
/***
* Adds a ProtocolCommandListener. Delegates this task to
* {@link #_commandSupport_ _commandSupport_ }.
@@ -1382,3 +1413,11 @@
}
}
+
+/* Emacs configuration
+ * Local variables: **
+ * mode: java **
+ * c-basic-offset: 4 **
+ * indent-tabs-mode: nil **
+ * End: **
+ */
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org