commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwins...@apache.org
Subject svn commit: r629541 - in /commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net: ftp/FTP.java ftp/FTPClient.java io/FromNetASCIIInputStream.java
Date Wed, 20 Feb 2008 17:46:38 GMT
Author: rwinston
Date: Wed Feb 20 09:46:30 2008
New Revision: 629541

URL: http://svn.apache.org/viewvc?rev=629541&view=rev
Log:
* Add encoding for FromNetASCIIInputStream.java
* Add preliminary fix for NET-148 (blocker for 2.0)

Modified:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/io/FromNetASCIIInputStream.java

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java?rev=629541&r1=629540&r2=629541&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTP.java
Wed Feb 20 09:46:30 2008
@@ -220,6 +220,13 @@
     protected boolean _newReplyString;
     protected String _replyString;
     protected String _controlEncoding;
+    
+    /**
+     * This is used to signal whether a block of multiline responses beginning
+     * with xxx must be terminated by the same numeric code xxx
+     * See section 4.2 of RFX 959 for details. 
+     */
+    protected boolean strictMultilineParsing = false;
 
     /**
      * Wraps SocketClient._input_ to facilitate the writing of text
@@ -261,6 +268,17 @@
         _controlEncoding = DEFAULT_CONTROL_ENCODING;
     }
 
+    
+    private boolean __strictCheck(String line, String code) {
+    	return (line.startsWith(code));
+    }
+    
+    private boolean __lenientCheck(String line) {
+    	return (!(line.length() >= 4 && line.charAt(3) != '-' &&
+                Character.isDigit(line.charAt(0))));
+    }
+    
+    
     private void __getReply() throws IOException
     {
         int length;
@@ -280,10 +298,11 @@
         if (length < 3)
             throw new MalformedServerReplyException(
                 "Truncated server reply: " + line);
-
+        
+        String code = null;
         try
         {
-            String code = line.substring(0, 3);
+            code = line.substring(0, 3);
             _replyCode = Integer.parseInt(code);
         }
         catch (NumberFormatException e)
@@ -311,8 +330,7 @@
                 // returning too soon after encountering a naked CR or some other
                 // anomaly.
             }
-            while (!(line.length() >= 4 && line.charAt(3) != '-' &&
-                     Character.isDigit(line.charAt(0))));
+            while ( isStrictMultilineParsing() ? __strictCheck(line, code) : __lenientCheck(line));
             // This is too strong a condition because of non-conforming ftp
             // servers like ftp.funet.fi which sent 226 as the last line of a
             // 426 multi-line reply in response to ls /.  We relax the condition to
@@ -1457,6 +1475,21 @@
         return sendCommand(FTPCommand.NOOP);
     }
 
+    /**
+     * Return whether strict multiline parsing is enabled, as per RFX 959, section 4.2.
+     * @return True if strict, false if lenient
+     */
+	public boolean isStrictMultilineParsing() {
+		return strictMultilineParsing;
+	}
+
+	/**
+	 * Set strict multiline parsing.
+	 * @param strictMultilineParsing
+	 */
+	public void setStrictMultilineParsing(boolean strictMultilineParsing) {
+		this.strictMultilineParsing = strictMultilineParsing;
+	}
 }
 
 /* Emacs configuration

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java?rev=629541&r1=629540&r2=629541&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/ftp/FTPClient.java
Wed Feb 20 09:46:30 2008
@@ -27,7 +27,6 @@
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.ArrayList;
-import java.util.Arrays;
 
 import org.apache.commons.net.MalformedServerReplyException;
 import org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory;
@@ -285,9 +284,9 @@
     
     private FTPClientConfig __configuration;
 
+    /** Pattern for PASV mode responses */ 
     private static String __parms = "\\d{1,3},\\d{1,3},\\d{1,3},\\d{1,3},\\d{1,3},\\d{1,3}";
     private static java.util.regex.Pattern __parms_pat;
-
     static {
        __parms_pat = java.util.regex.Pattern.compile(__parms);
     }
@@ -1277,7 +1276,7 @@
         input = new BufferedInputStream(socket.getInputStream(),
                                         getBufferSize());
         if (__fileType == ASCII_FILE_TYPE)
-          input = new FromNetASCIIInputStream(input);
+          input = new FromNetASCIIInputStream(input, getControlEncoding());
         // Treat everything else as binary for now
         try
         {
@@ -1342,7 +1341,7 @@
           // for file types other than ASCII.
           input = new BufferedInputStream(input,
                                           getBufferSize());
-          input = new FromNetASCIIInputStream(input);
+          input = new FromNetASCIIInputStream(input, getControlEncoding());
         }
         return new org.apache.commons.net.io.SocketInputStream(socket, input);
     }

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/io/FromNetASCIIInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/io/FromNetASCIIInputStream.java?rev=629541&r1=629540&r2=629541&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/io/FromNetASCIIInputStream.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/io/FromNetASCIIInputStream.java
Wed Feb 20 09:46:30 2008
@@ -20,6 +20,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 
 /***
  * This class wraps an input stream, replacing all occurrences
@@ -41,7 +43,6 @@
     static {
         _lineSeparator = System.getProperty("line.separator");
         _noConversionRequired = _lineSeparator.equals("\r\n");
-        _lineSeparatorBytes = _lineSeparator.getBytes(); // TODO specify encoding
     }
 
     private int __length = 0;
@@ -63,13 +64,28 @@
     /***
      * Creates a FromNetASCIIInputStream instance that wraps an existing
      * InputStream.
+     * @param input The {@link InputStream} instance
+     * @param encoding A character set encoding specifier
+     * 
+     * @throws UnsupportedEncodingException 
      ***/
-    public FromNetASCIIInputStream(InputStream input)
+    public FromNetASCIIInputStream(InputStream input, String encoding) throws UnsupportedEncodingException
     {
         super(input, _lineSeparatorBytes.length + 1);
+        _lineSeparatorBytes = _lineSeparator.getBytes(encoding); 
     }
-
-
+    
+    /**
+     * Creates a FromNetASCIIInputStream instance that wraps an existing
+     * InputStream.
+     * @param input An {@link InputStream} instance
+     * @throws UnsupportedEncodingException
+     */
+    public FromNetASCIIInputStream(InputStream input) throws UnsupportedEncodingException

+    {
+    	this(input, Charset.defaultCharset().name()); 
+    }
+    
     private int __read() throws IOException
     {
         int ch;



Mime
View raw message