commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jul...@apache.org
Subject svn commit: r1061980 - /commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64InputStreamTest.java
Date Fri, 21 Jan 2011 19:39:12 GMT
Author: julius
Date: Fri Jan 21 19:39:11 2011
New Revision: 1061980

URL: http://svn.apache.org/viewvc?rev=1061980&view=rev
Log:
Fix for CODEC-101:  java.io.InputStreamReader hates it when InputStream.read(byte[]) returns
a zero. (Adding an extra JUnit Test for good luck.)

Modified:
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64InputStreamTest.java

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64InputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64InputStreamTest.java?rev=1061980&r1=1061979&r2=1061980&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64InputStreamTest.java
(original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64InputStreamTest.java
Fri Jan 21 19:39:11 2011
@@ -17,8 +17,10 @@
 
 package org.apache.commons.codec.binary;
 
+import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.util.Arrays;
 
 import junit.framework.TestCase;
@@ -65,6 +67,35 @@ public class Base64InputStreamTest exten
     }
 
     /**
+     * Another test for the CODEC-101 bug:
+     * In commons-codec-1.4 this test shows InputStreamReader explicitly hating an
+     * InputStream.read(byte[]) return of 0:
+     *
+     * java.io.IOException: Underlying input stream returned zero bytes
+     * at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:268)
+     * at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
+     * at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
+     * at java.io.InputStreamReader.read(InputStreamReader.java:167)
+     * at java.io.BufferedReader.fill(BufferedReader.java:136)
+     * at java.io.BufferedReader.readLine(BufferedReader.java:299)
+     * at java.io.BufferedReader.readLine(BufferedReader.java:362)
+     * at org.apache.commons.codec.binary.Base64InputStreamTest.testInputStreamReader(Base64InputStreamTest.java:75)
+     *
+     * But in commons-codec-1.5 it's fixed.  :-)
+     *
+     * @throws Exception for some failure scenarios.
+     */
+    public void testInputStreamReader() throws Exception {
+        byte[] codec101 = StringUtils.getBytesUtf8(Base64TestData.CODEC_101_MULTIPLE_OF_3);
+        ByteArrayInputStream bais = new ByteArrayInputStream(codec101);
+        Base64InputStream in = new Base64InputStream(bais);
+        InputStreamReader isr = new InputStreamReader(in);
+        BufferedReader br = new BufferedReader(isr);
+        String line = br.readLine();
+        assertNotNull("Codec101:  InputStreamReader works!", line);
+    }
+
+    /**
      * Test the Base64InputStream implementation against the special NPE inducing input
      * identified in the CODEC-98 bug.
      *



Mime
View raw message