|
17 | 17 |
|
18 | 18 | package org.apache.commons.codec.binary; |
19 | 19 |
|
| 20 | +import java.io.BufferedReader; |
20 | 21 | import java.io.ByteArrayInputStream; |
21 | 22 | import java.io.InputStream; |
| 23 | +import java.io.InputStreamReader; |
22 | 24 | import java.util.Arrays; |
23 | 25 |
|
24 | 26 | import junit.framework.TestCase; |
@@ -64,6 +66,35 @@ public void testCodec101() throws Exception { |
64 | 66 | assertTrue("Codec101: Second read should report end-of-stream [c=" + c + "]", c < 0); |
65 | 67 | } |
66 | 68 |
|
| 69 | + /** |
| 70 | + * Another test for the CODEC-101 bug: |
| 71 | + * In commons-codec-1.4 this test shows InputStreamReader explicitly hating an |
| 72 | + * InputStream.read(byte[]) return of 0: |
| 73 | + * |
| 74 | + * java.io.IOException: Underlying input stream returned zero bytes |
| 75 | + * at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:268) |
| 76 | + * at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) |
| 77 | + * at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) |
| 78 | + * at java.io.InputStreamReader.read(InputStreamReader.java:167) |
| 79 | + * at java.io.BufferedReader.fill(BufferedReader.java:136) |
| 80 | + * at java.io.BufferedReader.readLine(BufferedReader.java:299) |
| 81 | + * at java.io.BufferedReader.readLine(BufferedReader.java:362) |
| 82 | + * at org.apache.commons.codec.binary.Base64InputStreamTest.testInputStreamReader(Base64InputStreamTest.java:75) |
| 83 | + * |
| 84 | + * But in commons-codec-1.5 it's fixed. :-) |
| 85 | + * |
| 86 | + * @throws Exception for some failure scenarios. |
| 87 | + */ |
| 88 | + public void testInputStreamReader() throws Exception { |
| 89 | + byte[] codec101 = StringUtils.getBytesUtf8(Base64TestData.CODEC_101_MULTIPLE_OF_3); |
| 90 | + ByteArrayInputStream bais = new ByteArrayInputStream(codec101); |
| 91 | + Base64InputStream in = new Base64InputStream(bais); |
| 92 | + InputStreamReader isr = new InputStreamReader(in); |
| 93 | + BufferedReader br = new BufferedReader(isr); |
| 94 | + String line = br.readLine(); |
| 95 | + assertNotNull("Codec101: InputStreamReader works!", line); |
| 96 | + } |
| 97 | + |
67 | 98 | /** |
68 | 99 | * Test the Base64InputStream implementation against the special NPE inducing input |
69 | 100 | * identified in the CODEC-98 bug. |
|
0 commit comments