harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r824191 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java
Date Sun, 11 Oct 2009 22:45:10 GMT
Author: ndbeyer
Date: Sun Oct 11 22:45:09 2009
New Revision: 824191

URL: http://svn.apache.org/viewvc?rev=824191&view=rev
Log:
rework reply code read so that it's not ignore read byte count; reuse the replyCode String;
catch parsing exception and convert it to an IOException

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java?rev=824191&r1=824190&r2=824191&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java
Sun Oct 11 22:45:09 2009
@@ -18,6 +18,7 @@
 package org.apache.harmony.luni.internal.net.www.protocol.ftp;
 
 import java.io.BufferedInputStream;
+import java.io.EOFException;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -334,7 +335,6 @@
      * @see java.io.IOException
      * 
      */
-
     @Override
     public OutputStream getOutputStream() throws IOException {
         if (!connected) {
@@ -345,8 +345,15 @@
 
     private int getReply() throws IOException {
         byte[] code = new byte[3];
-        ctrlInput.read(code, 0, code.length);
+        for (int i = 0; i < code.length; i++) {
+            final int tmp = ctrlInput.read();
+            if (tmp == -1) {
+                throw new EOFException();
+            }
+            code[i] = (byte) tmp;
+        }
         replyCode = new String(code, "ISO8859_1"); //$NON-NLS-1$
+        
         boolean multiline = false;
         if (ctrlInput.read() == '-') {
             multiline = true;
@@ -356,7 +363,12 @@
             while (readMultiLine()) {/* Read all of a multiline reply */
             }
         }
-        return Integer.parseInt(new String(code, "ISO8859_1")); //$NON-NLS-1$
+        
+        try {
+            return Integer.parseInt(replyCode);
+        } catch (NumberFormatException e) {
+            throw (IOException)(new IOException("reply code is invalid").initCause(e));
+        }
     }
 
     private void login() throws IOException {



Mime
View raw message