commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1052095 - in /commons/proper/io/trunk/src: main/java/org/apache/commons/io/input/BOMInputStream.java test/java/org/apache/commons/io/input/BOMInputStreamTest.java
Date Wed, 22 Dec 2010 23:03:20 GMT
Author: niallp
Date: Wed Dec 22 23:03:20 2010
New Revision: 1052095

URL: http://svn.apache.org/viewvc?rev=1052095&view=rev
Log:
IO-257 Fix BOMInputStream's read(byte[]) can return 0 which it should not - thanks to Teemu
Lång

Modified:
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/BOMInputStream.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/BOMInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/BOMInputStream.java?rev=1052095&r1=1052094&r2=1052095&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/BOMInputStream.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/BOMInputStream.java
Wed Dec 22 23:03:20 2010
@@ -284,7 +284,7 @@ public class BOMInputStream extends Prox
             }
         }
         int secondCount = in.read(buf, off, len);
-        return (secondCount < 0) ? firstCount : firstCount + secondCount;
+        return (secondCount < 0) ? (firstCount > 0 ? firstCount : -1) : firstCount
+ secondCount;
     }
 
     /**

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java?rev=1052095&r1=1052094&r2=1052095&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java
Wed Dec 22 23:03:20 2010
@@ -204,6 +204,20 @@ public class BOMInputStreamTest extends 
         assertEquals("getBOM", ByteOrderMark.UTF_8, in.getBOM());
     }
 
+    public void testEmptyBufferWithoutBOM() throws Exception {
+        byte[] data = new byte[] {};
+        InputStream in = new BOMInputStream(createDataStream(data, false));
+        byte[] buf = new byte[1024];
+        assertEquals(-1, in.read(buf));
+    }
+
+    public void testEmptyBufferWithBOM() throws Exception {
+        byte[] data = new byte[] {};
+        InputStream in = new BOMInputStream(createDataStream(data, true));
+        byte[] buf = new byte[1024];
+        assertEquals(-1, in.read(buf));
+    }
+
     public void testLargeBufferWithoutBOM() throws Exception {
         byte[] data = new byte[] { 'A', 'B', 'C' };
         InputStream in = new BOMInputStream(createDataStream(data, false));



Mime
View raw message