Author: ggregory
Date: Mon Mar 19 19:48:00 2012
New Revision: 1302622

URL: http://svn.apache.org/viewvc?rev=1302622&view=rev
Log:
[CODEC-130] Base64InputStream.skip skips underlying stream, not output. Better 
exception information. Less verbose code with a single return. Order methods AB.

Modified:
    
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java

Modified: 
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java?rev=1302622&r1=1302621&r2=1302622&view=diff
==============================================================================
--- 
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
 (original)
+++ 
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
 Mon Mar 19 19:48:00 2012
@@ -30,10 +30,10 @@ import java.io.InputStream;
  */
 public class BaseNCodecInputStream extends FilterInputStream {
 
-    private final boolean doEncode;
-
     private final BaseNCodec baseNCodec;
 
+    private final boolean doEncode;
+
     private final byte[] singleByte = new byte[1];
 
     protected BaseNCodecInputStream(InputStream in, BaseNCodec baseNCodec, 
boolean doEncode) {
@@ -43,6 +43,31 @@ public class BaseNCodecInputStream exten
     }
 
     /**
+     * {@inheritDoc}
+     *
+     * @return <code>0</code> if the {@link InputStream} has reached 
<code>EOF</code>,
+     * <code>1</code> otherwise
+     */
+    public int available() throws IOException {
+        // Note: the logic is similar to the InflaterInputStream:
+        //       as long as we have not reached EOF, indicate that there is 
more
+        //       data available. As we do not know for sure how much data is 
left,
+        //       just return 1 as a safe guess.
+
+        // use the EOF flag of the underlying codec instance
+        return baseNCodec.eof ? 0 : 1;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @return false
+     */
+    @Override
+    public boolean markSupported() {
+        return false; // not an easy job to support marks
+    }
+    /**
      * Reads one <code>byte</code> from this input stream.
      * 
      * @return the byte as an integer in the range 0 to 255. Returns -1 if EOF 
has been reached.
@@ -124,15 +149,6 @@ public class BaseNCodecInputStream exten
             return readLen;
         }
     }
-    /**
-     * {@inheritDoc}
-     * 
-     * @return false
-     */
-    @Override
-    public boolean markSupported() {
-        return false; // not an easy job to support marks
-    }
 
     /**
      * {@inheritDoc}
@@ -142,7 +158,7 @@ public class BaseNCodecInputStream exten
     @Override
     public long skip(long n) throws IOException {
         if (n < 0) {
-            throw new IllegalArgumentException("Negative skip length");
+            throw new IllegalArgumentException("Negative skip length: " + n);
         }
 
         // skip in chunks of 512 bytes
@@ -164,24 +180,4 @@ public class BaseNCodecInputStream exten
 
         return total;
     }
-
-    /**
-     * {@inheritDoc}
-     *
-     * @return <code>0</code> if the {@link InputStream} has reached 
<code>EOF</code>,
-     * <code>1</code> otherwise
-     */
-    public int available() throws IOException {
-        // Note: the logic is similar to the InflaterInputStream:
-        //       as long as we have not reached EOF, indicate that there is 
more
-        //       data available. As we do not know for sure how much data is 
left,
-        //       just return 1 as a safe guess.
-
-        // use the EOF flag of the underlying codec instance
-        if (baseNCodec.eof) {
-            return 0;
-        } else {
-            return 1;
-        }
-    }
 }


Reply via email to