Skip to content

Commit d108068

Browse files
author
Robert James Oxspring
committed
CountingInputStream now implements skip(long) method.
PR: 34311 git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@160202 13f79535-47bb-0310-9956-ffa450edef68
1 parent 022d817 commit d108068

3 files changed

Lines changed: 43 additions & 6 deletions

File tree

project.xml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
-->
1717
<project>
1818
<pomVersion>3</pomVersion>
19-
19+
2020
<name>IO</name>
2121
<id>commons-io</id>
2222
<currentVersion>1.1-dev</currentVersion>
@@ -26,7 +26,7 @@
2626
Commons-IO contains utility classes, stream implementations, file filters, and endian classes.
2727
</description>
2828
<logo>/images/io-logo-white.png</logo>
29-
29+
3030
<url>http://jakarta.apache.org/commons/${pom.artifactId.substring(8)}/</url>
3131
<package>org.apache.commons.${pom.artifactId.substring(8)}</package>
3232

@@ -43,18 +43,18 @@
4343
<distribution>repo</distribution>
4444
</license>
4545
</licenses>
46-
46+
4747
<gumpRepositoryId>jakarta</gumpRepositoryId>
4848
<issueTrackingUrl>http://issues.apache.org/bugzilla/</issueTrackingUrl>
4949
<siteAddress>jakarta.apache.org</siteAddress>
5050
<siteDirectory>/www/jakarta.apache.org/commons/${pom.artifactId.substring(8)}/</siteDirectory>
5151
<distributionDirectory>/www/jakarta.apache.org/builds/jakarta-commons/${pom.artifactId.substring(8)}/</distributionDirectory>
52-
52+
5353
<repository>
5454
<connection>scm:svn:http://svn.apache.org/repos/asf/jakarta/commons/proper/${pom.artifactId.substring(8)}/trunk</connection>
5555
<url>http://svn.apache.org/repos/asf/jakarta/commons/proper/${pom.artifactId.substring(8)}/trunk</url>
5656
</repository>
57-
57+
5858
<mailingLists>
5959
<mailingList>
6060
<name>Commons Dev List</name>
@@ -69,7 +69,7 @@
6969
<archive>http://mail-archives.apache.org/eyebrowse/SummarizeList?listName=commons-user@jakarta.apache.org</archive>
7070
</mailingList>
7171
</mailingLists>
72-
72+
7373
<versions>
7474
<version>
7575
<id>1.0</id>
@@ -151,6 +151,15 @@
151151
<role>Java Developer</role>
152152
</roles>
153153
</developer>
154+
<developer>
155+
<name>Rob Oxspring</name>
156+
<id>roxspring</id>
157+
<email>roxspring@apache.org</email>
158+
<organization/>
159+
<roles>
160+
<role>Java Developer</role>
161+
</roles>
162+
</developer>
154163

155164
</developers>
156165

src/java/org/apache/commons/io/input/CountingInputStream.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ public int read() throws IOException {
7171
this.count += (found >= 0) ? 1 : 0;
7272
return found;
7373
}
74+
75+
/**
76+
* Increases the count by the number of skipped bytes.
77+
*
78+
* @see java.io.InputStream#skip(long)
79+
*/
80+
public long skip(final long length) throws IOException {
81+
final long skip = super.skip(length);
82+
this.count += skip;
83+
return skip;
84+
}
7485

7586
/**
7687
* The number of bytes that have passed through this stream.

src/test/org/apache/commons/io/input/CountingInputStreamTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.apache.commons.io.input;
1818

1919
import java.io.ByteArrayInputStream;
20+
import java.io.IOException;
21+
import java.util.Arrays;
2022

2123
import junit.framework.TestCase;
2224

@@ -149,5 +151,20 @@ public void testEOF3() throws Exception {
149151
assertEquals(2, found);
150152
assertEquals(2, cis.getCount());
151153
}
154+
155+
public void testSkipping() throws IOException {
156+
String text = "Hello World!";
157+
byte[] bytes = text.getBytes();
158+
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
159+
CountingInputStream cis = new CountingInputStream(bais);
160+
161+
assertEquals(6,cis.skip(6));
162+
assertEquals(6,cis.getCount());
163+
final byte[] result = new byte[6];
164+
cis.read(result);
165+
166+
assertEquals("World!",new String(result));
167+
assertEquals(12,cis.getCount());
168+
}
152169

153170
}

0 commit comments

Comments
 (0)