Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 2446 invoked from network); 4 Apr 2005 16:12:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 4 Apr 2005 16:12:50 -0000 Received: (qmail 72405 invoked by uid 500); 4 Apr 2005 16:12:46 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 72339 invoked by uid 500); 4 Apr 2005 16:12:46 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 72324 invoked by uid 99); 4 Apr 2005 16:12:46 -0000 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from out1.smtp.messagingengine.com (HELO out1.smtp.messagingengine.com) (66.111.4.25) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 04 Apr 2005 09:12:45 -0700 Received: from frontend3.messagingengine.com (frontend3.internal [10.202.2.152]) by frontend1.messagingengine.com (Postfix) with ESMTP id E1E83C7081E for ; Mon, 4 Apr 2005 12:12:41 -0400 (EDT) X-Sasl-enc: aGa2seys4zi6avTlYjUzMA 1112631161 Received: from [172.16.155.125] (host217-39-36-110.in-addr.btopenworld.com [217.39.36.110]) by www.fastmail.fm (Postfix) with ESMTP id A0E6025535 for ; Mon, 4 Apr 2005 12:12:41 -0400 (EDT) Message-ID: <4251676E.7020101@imapmail.org> Date: Mon, 04 Apr 2005 17:12:30 +0100 From: Rob Oxspring User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jakarta Commons Developers List Subject: [io][patch] skip() support for CountingInputStream Content-Type: multipart/mixed; boundary="------------050204030101010200090603" X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------050204030101010200090603 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, I recently replaced the use of my own CountingInputStream with the commons-io and got burnt because io's CountingInputStream doesn't count skipped bytes. I have a patch with fix and patch if people are interested... or I could just commit it... Thoughts? Rob --------------050204030101010200090603 Content-Type: text/plain; name="CountingInputStream_skip_implementation.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="CountingInputStream_skip_implementation.patch" Index: src/test/org/apache/commons/io/input/CountingInputStreamTest.java =================================================================== --- src/test/org/apache/commons/io/input/CountingInputStreamTest.java (revision 160052) +++ src/test/org/apache/commons/io/input/CountingInputStreamTest.java (working copy) @@ -17,6 +17,8 @@ package org.apache.commons.io.input; import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Arrays; import junit.framework.TestCase; @@ -149,5 +151,20 @@ assertEquals(2, found); assertEquals(2, cis.getCount()); } + + public void testSkipping() throws IOException { + String text = "Hello World!"; + byte[] bytes = text.getBytes(); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + CountingInputStream cis = new CountingInputStream(bais); + + assertEquals(6,cis.skip(6)); + assertEquals(6,cis.getCount()); + final byte[] result = new byte[6]; + cis.read(result); + + assertEquals("World!",new String(result)); + assertEquals(12,cis.getCount()); + } } Index: src/java/org/apache/commons/io/input/CountingInputStream.java =================================================================== --- src/java/org/apache/commons/io/input/CountingInputStream.java (revision 160052) +++ src/java/org/apache/commons/io/input/CountingInputStream.java (working copy) @@ -71,6 +71,17 @@ this.count += (found >= 0) ? 1 : 0; return found; } + + /** + * Increases the count by the number of skipped bytes. + * + * @see java.io.InputStream#skip(long) + */ + public long skip(final long length) throws IOException { + final long skip = super.skip(length); + this.count += skip; + return skip; + } /** * The number of bytes that have passed through this stream. --------------050204030101010200090603 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org --------------050204030101010200090603--