Author: toad
Date: 2006-12-02 20:34:29 +0000 (Sat, 02 Dec 2006)
New Revision: 11204
Added:
trunk/freenet/src/freenet/support/io/CountedInputStream.java
Log:
Doh
Added: trunk/freenet/src/freenet/support/io/CountedInputStream.java
===================================================================
--- trunk/freenet/src/freenet/support/io/CountedInputStream.java
2006-12-02 20:01:33 UTC (rev 11203)
+++ trunk/freenet/src/freenet/support/io/CountedInputStream.java
2006-12-02 20:34:29 UTC (rev 11204)
@@ -0,0 +1,38 @@
+package freenet.support.io;
+
+import java.io.*;
+
+public class CountedInputStream extends FilterInputStream {
+
+ protected long count = 0;
+
+ public CountedInputStream(InputStream in) {
+ super(in);
+ if(in == null) throw new IllegalStateException("null fed to
CountedInputStream");
+ }
+
+ public final long count() {
+ return count;
+ }
+
+ public int read() throws IOException {
+ int ret = super.read();
+ if (ret != -1)
+ ++count;
+ return ret;
+ }
+
+ public int read(byte[] buf, int off, int len) throws IOException {
+ int ret = super.read(buf, off, len);
+ if (ret != -1)
+ count += ret;
+ return ret;
+ }
+
+ public long skip(int n) throws IOException {
+ long l = in.skip(n);
+ if(l > 0) count += l;
+ return l;
+ }
+}
+