james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1606057 - in /james/mime4j/trunk/core/src: main/java/org/apache/james/mime4j/io/TextInputStream.java test/java/org/apache/james/mime4j/io/TextInputStreamTest.java
Date Fri, 27 Jun 2014 12:29:23 GMT
Author: olegk
Date: Fri Jun 27 12:29:23 2014
New Revision: 1606057

URL: http://svn.apache.org/r1606057
Log:
MIME4J-241: inconsistent StringInputStream read zero behavior

Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/TextInputStream.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/TextInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/TextInputStream.java?rev=1606057&r1=1606056&r2=1606057&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/TextInputStream.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/TextInputStream.java
Fri Jun 27 12:29:23 2014
@@ -67,9 +67,6 @@ class TextInputStream extends InputStrea
         if (off < 0 || len < 0 || off + len > b.length) {
             throw new IndexOutOfBoundsException();
         }
-        if (len == 0) {
-            return 0;
-        }
         if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) {
             return -1;
         }
@@ -88,7 +85,15 @@ class TextInputStream extends InputStrea
                 }
             }
         }
-        return bytesRead == 0 && !this.cbuf.hasRemaining() ? -1 : bytesRead;
+        if (bytesRead > 0) {
+            return bytesRead;
+        } else {
+            if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) {
+                return -1;
+            } else {
+                return bytesRead;
+            }
+        }
     }
 
     @Override

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java?rev=1606057&r1=1606056&r2=1606057&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/TextInputStreamTest.java
Fri Jun 27 12:29:23 2014
@@ -115,6 +115,18 @@ public class TextInputStreamTest {
     }
 
     @Test
+    public void testReadZero2() throws Exception {
+        InputStream r = new TextInputStream("test", Charsets.US_ASCII, 1024);
+        byte[] bytes = new byte[30];
+        assertEquals(2, r.read(bytes, 0, 2));
+        assertEquals(0, r.read(bytes, 2, 0));
+        assertEquals(0, r.read(bytes, 2, 0));
+        assertEquals(2, r.read(bytes, 2, 2));
+        assertEquals(-1, r.read(bytes, 4, 0));
+        assertEquals(-1, r.read(bytes, 4, 2));
+    }
+
+    @Test
     public void testSkip() throws Exception {
         InputStream r = new TextInputStream("test", Charsets.UTF_8, 1024);
         r.skip(1);



Mime
View raw message