org.apache.commons.io.input
Class CountingInputStream
java.lang.Object
|
+--java.io.InputStream
|
+--java.io.FilterInputStream
|
+--org.apache.commons.io.input.ProxyInputStream
|
+--org.apache.commons.io.input.CountingInputStream
- public class CountingInputStream
- extends ProxyInputStream
A decorating input stream that counts the number of bytes that
have passed through so far.
- Version:
- $Id: CountingInputStream.java 160202 2005-04-05 17:22:21Z roxspring $
- Author:
- Henri Yandell, Marcelo Liberato
Field Summary |
private int |
count
The count of bytes that have passed. |
Fields inherited from class java.io.FilterInputStream |
in |
Fields inherited from class java.io.InputStream |
SKIP_BUFFER_SIZE, skipBuffer |
Constructor Summary |
CountingInputStream(java.io.InputStream in)
Constructs a new CountingInputStream. |
Method Summary |
int |
getCount()
The number of bytes that have passed through this stream. |
int |
read()
Increases the count by 1 if a byte is successfully read. |
int |
read(byte[] b)
Increases the count by super.read(b)'s return count |
int |
read(byte[] b,
int off,
int len)
Increases the count by super.read(b, off, len)'s return count |
int |
resetCount()
Set the count back to 0. |
long |
skip(long length)
Increases the count by the number of skipped bytes. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
count
private int count
- The count of bytes that have passed.
CountingInputStream
public CountingInputStream(java.io.InputStream in)
- Constructs a new CountingInputStream.
- Parameters:
in
- InputStream to delegate to
read
public int read(byte[] b)
throws java.io.IOException
- Increases the count by super.read(b)'s return count
- Overrides:
read
in class ProxyInputStream
- See Also:
InputStream.read(byte[])
read
public int read(byte[] b,
int off,
int len)
throws java.io.IOException
- Increases the count by super.read(b, off, len)'s return count
- Overrides:
read
in class ProxyInputStream
- See Also:
InputStream.read(byte[], int, int)
read
public int read()
throws java.io.IOException
- Increases the count by 1 if a byte is successfully read.
- Overrides:
read
in class ProxyInputStream
- See Also:
InputStream.read()
skip
public long skip(long length)
throws java.io.IOException
- Increases the count by the number of skipped bytes.
- Overrides:
skip
in class ProxyInputStream
- See Also:
InputStream.skip(long)
getCount
public int getCount()
- The number of bytes that have passed through this stream.
- Returns:
- the number of bytes accumulated
resetCount
public int resetCount()
- Set the count back to 0.
- Returns:
- the count previous to resetting.