You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2004/12/03 15:47:47 UTC

cvs commit: jakarta-commons/net/src/java/org/apache/commons/net/ftp FTPClient.java FTPFileEntryParserImpl.java FTPFileList.java FTPFileListParser.java FTPListParseEngine.java

rwinston    2004/12/03 06:47:46

  Modified:    net/src/java/org/apache/commons/net/ftp FTPClient.java
                        FTPFileEntryParserImpl.java FTPFileList.java
                        FTPFileListParser.java FTPListParseEngine.java
  Log:
  Update FTPClient code to use the user-specified encoding throughout the entire FTPClient codebase. These changes are taken from the patch for PR 30719. The next candidate for updating is any/all instances of String.getBytes() that don;'t pass the encoding.
  
  Revision  Changes    Path
  1.46      +3 -3      jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPClient.java
  
  Index: FTPClient.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPClient.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- FTPClient.java	23 Nov 2004 19:57:12 -0000	1.45
  +++ FTPClient.java	3 Dec 2004 14:47:46 -0000	1.46
  @@ -1945,7 +1945,7 @@
               return null;
   
           reader =
  -            new BufferedReader(new InputStreamReader(socket.getInputStream()));
  +            new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()));
   
           results = new Vector();
           while ((line = reader.readLine()) != null)
  @@ -2359,7 +2359,7 @@
           }
   
   
  -        engine.readServerList(socket.getInputStream());
  +        engine.readServerList(socket.getInputStream(), getControlEncoding());
   
           socket.close();
   
  @@ -2454,7 +2454,7 @@
           if ((socket = _openDataConnection_(FTPCommand.LIST, pathname)) == null)
               return new FTPFile[0];
   
  -        results = parser.parseFileList(socket.getInputStream());
  +        results = parser.parseFileList(socket.getInputStream(), getControlEncoding());
   
           socket.close();
   
  
  
  
  1.9       +23 -2     jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPFileEntryParserImpl.java
  
  Index: FTPFileEntryParserImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPFileEntryParserImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FTPFileEntryParserImpl.java	22 Apr 2004 00:48:07 -0000	1.8
  +++ FTPFileEntryParserImpl.java	3 Dec 2004 14:47:46 -0000	1.9
  @@ -52,11 +52,32 @@
        *     the directory.
        * @exception java.io.IOException  If an I/O error occurs reading the listStream.
        ***/
  -    public FTPFile[] parseFileList(InputStream listStream) throws IOException
  +    public FTPFile[] parseFileList(InputStream listStream, String encoding) throws IOException
       {
  -        FTPFileList ffl = FTPFileList.create(listStream, this);
  +        FTPFileList ffl = FTPFileList.create(listStream, this, encoding);
           return ffl.getFiles();
   
  +    }
  +    
  +    /***
  +     * Parses an FTP server file listing and converts it into a usable format
  +     * in the form of an array of <code> FTPFile </code> instances.  If the
  +     * file list contains no files, <code> null </code> should be
  +     * returned, otherwise an array of <code> FTPFile </code> instances
  +     * representing the files in the directory is returned.
  +     * <p>
  +     * @param listStream The InputStream from which the file list should be
  +     *        read.
  +     * @return The list of file information contained in the given path.  null
  +     *     if the list could not be obtained or if there are no files in
  +     *     the directory.
  +     * @exception java.io.IOException  If an I/O error occurs reading the listStream.
  +     *
  +     * @deprecated The version of this method which takes an encoding should be used.
  +    ***/
  +    public FTPFile[] parseFileList(InputStream listStream) throws IOException
  +    {
  +    	return parseFileList(listStream, null);
       }
   
       /**
  
  
  
  1.14      +56 -8     jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPFileList.java
  
  Index: FTPFileList.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPFileList.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- FTPFileList.java	21 Apr 2004 23:30:33 -0000	1.13
  +++ FTPFileList.java	3 Dec 2004 14:47:46 -0000	1.14
  @@ -65,8 +65,9 @@
        *
        * @param parser a <code>FTPFileEntryParser</code> value that knows
        * how to parse the entries returned by a particular FTP site.
  +     * @param encoding The encoding to use.
        */
  -    private FTPFileList (FTPFileEntryParser parser)
  +    private FTPFileList (FTPFileEntryParser parser, String encoding)
       {
           this.parser = parser;
           this.lines = new LinkedList();
  @@ -82,6 +83,7 @@
        * the output of the LIST command was returned
        * @param parser the default <code>FTPFileEntryParser</code> to be used
        * by this object.  This may later be changed using the init() method.
  +     * @param encoding The encoding to use
        *
        * @return the <code>FTPFileList</code> created, with an initialized
        * of unparsed lines of output.  Will be null if the listing cannot
  @@ -90,26 +92,55 @@
        *                   Thrown on any failure to read from the socket.
        */
       public static FTPFileList create(InputStream stream,
  -                                      FTPFileEntryParser parser)
  +                                      FTPFileEntryParser parser,
  +									  String encoding)
               throws IOException
       {
  -        FTPFileList list = new FTPFileList(parser);
  -        list.readStream(stream);
  +        FTPFileList list = new FTPFileList(parser, encoding);
  +        list.readStream(stream, encoding);
           parser.preParse(list.lines);
           return list;
       }
  +    
  +    /**
  +     * The only way to create an <code>FTPFileList</code> object.  Invokes
  +     * the private constructor and then reads the stream  supplied stream to
  +     * build the intermediate array of "lines" which will later be parsed
  +     * into <code>FTPFile</code> object.
  +     *
  +     * @param stream The input stream created by reading the socket on which
  +     * the output of the LIST command was returned
  +     * @param parser the default <code>FTPFileEntryParser</code> to be used
  +     * by this object.  This may later be changed using the init() method.
  +     *
  +     * @return the <code>FTPFileList</code> created, with an initialized
  +     * of unparsed lines of output.  Will be null if the listing cannot
  +     * be read from the stream.
  +     * @exception IOException
  +     *                   Thrown on any failure to read from the socket.
  +     *
  +     * @deprecated The version of this method which takes an encoding should be used.
  +    */
  +    public static FTPFileList create(InputStream stream, 
  +    								  FTPFileEntryParser parser)
  +    	throws IOException
  +    {
  +    	return create(stream, parser, null);
  +    }
  +    
  +    
   
       /**
        * internal method for reading the input into the <code>lines</code> vector.
        *
        * @param stream The socket stream on which the input will be read.
  +     * @param encoding The encoding to use.
        *
        * @exception IOException thrown on any failure to read the stream
        */
  -    public void readStream(InputStream stream) throws IOException
  +    public void readStream(InputStream stream, String encoding) throws IOException
       {
  -        BufferedReader reader =
  -            new BufferedReader(new InputStreamReader(stream));
  +        BufferedReader reader = new BufferedReader(new InputStreamReader(stream, encoding));
   
           String line = this.parser.readNextEntry(reader);
   
  @@ -120,6 +151,21 @@
           }
           reader.close();
       }
  +    
  +    /**
  +	 * internal method for reading the input into the <code>lines</code> vector.
  +	 *
  +	 * @param stream The socket stream on which the input will be read.
  +	 *
  +	 * @exception IOException thrown on any failure to read the stream
  +	 *
  +	 * @deprecated The version of this method which takes an encoding should be used.
  +	*/
  +	public void readStream(InputStream stream) throws IOException
  +	{
  +	 readStream(stream, null);
  +	}
  +	 
   
       /**
        * Accessor for this object's default parser.
  @@ -177,6 +223,8 @@
       {
           return iterator().getFiles();
       }
  +    
  +
   
   }
   
  
  
  
  1.13      +17 -0     jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPFileListParser.java
  
  Index: FTPFileListParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPFileListParser.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- FTPFileListParser.java	29 Jun 2004 02:16:33 -0000	1.12
  +++ FTPFileListParser.java	3 Dec 2004 14:47:46 -0000	1.13
  @@ -45,6 +45,23 @@
        * <p>
        * @param listStream The InputStream from which the file list should be
        *        read.
  +     * @param encoding The encoding to use.
  +     * @return The list of file information contained in the given path.  null
  +     *     if the list could not be obtained or if there are no files in
  +     *     the directory.
  +     * @exception IOException  If an I/O error occurs reading the listStream.
  +     ***/
  +    FTPFile[] parseFileList(InputStream listStream, String encoding) throws IOException;
  +    
  +    /***
  +     * Parses an FTP server file listing and converts it into a usable format
  +     * in the form of an array of <code> FTPFile </code> instances.  If the
  +     * file list contains no files, <code> null </code> should be
  +     * returned, otherwise an array of <code> FTPFile </code> instances
  +     * representing the files in the directory is returned.
  +     * <p>
  +     * @param listStream The InputStream from which the file list should be
  +     *        read.
        * @return The list of file information contained in the given path.  null
        *     if the list could not be obtained or if there are no files in
        *     the directory.
  
  
  
  1.9       +34 -7     jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPListParseEngine.java
  
  Index: FTPListParseEngine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/net/src/java/org/apache/commons/net/ftp/FTPListParseEngine.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FTPListParseEngine.java	15 Sep 2004 02:24:04 -0000	1.8
  +++ FTPListParseEngine.java	3 Dec 2004 14:47:46 -0000	1.9
  @@ -91,14 +91,34 @@
        * @exception IOException
        *                   thrown on any failure to read from the sever.
        */
  -    public void readServerList(InputStream stream)
  +    public void readServerList(InputStream stream, String encoding)
       throws IOException
       {
           this.entries = new LinkedList();
  -        readStream(stream);
  +        readStream(stream, encoding);
           this.parser.preParse(this.entries);
           resetIterator();
       }
  +    
  +    /**
  +	 * handle the iniitial reading and preparsing of the list returned by
  +	 * the server.  After this method has completed, this object will contain
  +	 * a list of unparsed entries (Strings) each referring to a unique file
  +	 * on the server.
  +	 *
  +	 * @param stream input stream provided by the server socket.
  +	 *
  +	 * @exception IOException
  +	 *                   thrown on any failure to read from the sever.
  +	 *
  +	 * @deprecated The version of this method which takes an encoding should be used.
  +	*/
  +	public void readServerList(InputStream stream)
  +	throws IOException
  +	{
  +		readServerList(stream, null);
  +	}
  +	
   
   
       /**
  @@ -114,11 +134,18 @@
        * @exception IOException
        *                   thrown on any failure to read the stream
        */
  -    private void readStream(InputStream stream) throws IOException
  +    private void readStream(InputStream stream, String encoding) throws IOException
       {
  -        BufferedReader reader =
  -            new BufferedReader(new InputStreamReader(stream));
  -
  +    	BufferedReader reader;
  +    	if (encoding == null)
  +    	{
  +    		reader = new BufferedReader(new InputStreamReader(stream));
  +    	}
  +    	else
  +    	{
  +    		reader = new BufferedReader(new InputStreamReader(stream, encoding));
  +    	}
  +    	
           String line = this.parser.readNextEntry(reader);
   
           while (line != null)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org