Return-Path: X-Original-To: apmail-james-mime4j-dev-archive@minotaur.apache.org Delivered-To: apmail-james-mime4j-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 013B811BC6 for ; Fri, 27 Jun 2014 12:29:46 +0000 (UTC) Received: (qmail 55064 invoked by uid 500); 27 Jun 2014 12:29:45 -0000 Delivered-To: apmail-james-mime4j-dev-archive@james.apache.org Received: (qmail 55028 invoked by uid 500); 27 Jun 2014 12:29:45 -0000 Mailing-List: contact mime4j-dev-help@james.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: mime4j-dev@james.apache.org Delivered-To: mailing list mime4j-dev@james.apache.org Received: (qmail 55017 invoked by uid 99); 27 Jun 2014 12:29:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jun 2014 12:29:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Jun 2014 12:29:44 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 26F2A238897A; Fri, 27 Jun 2014 12:29:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: mime4j-dev@james.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140627122924.26F2A238897A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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);