Skip to content

Commit 9c52bac

Browse files
committed
modified so that when a read(byte[]) method returns a different number of bytes read than requested, the count is correct
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@140414 13f79535-47bb-0310-9956-ffa450edef68
1 parent fc4d32f commit 9c52bac

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
* through it.
6363
*
6464
* @author <a href="mailto:bayard@apache.org">Henri Yandell</a>
65-
* @version $Id: CountingInputStream.java,v 1.3 2003/10/13 07:04:16 rdonkin Exp $
65+
* @version $Id: CountingInputStream.java,v 1.4 2003/11/23 09:18:55 bayard Exp $
6666
*/
67-
public class CountingInputStream extends FilterInputStream {
67+
public class CountingInputStream extends ProxyInputStream {
6868

6969
private int count;
7070

@@ -78,14 +78,16 @@ public CountingInputStream( InputStream in ) {
7878

7979
/** @see java.io.InputStream#read(byte[]) */
8080
public int read(byte[] b) throws IOException {
81-
count += b.length;
82-
return super.read(b);
81+
int found = super.read(b);
82+
count += found;
83+
return found;
8384
}
8485

8586
/** @see java.io.InputStream#read(byte[], int, int) */
8687
public int read(byte[] b, int off, int len) throws IOException {
87-
count += len;
88-
return super.read(b, off, len);
88+
int found = super.read(b, off, len);
89+
count += found;
90+
return found;
8991
}
9092

9193
/** @see java.io.InputStream#read() */

0 commit comments

Comments
 (0)