sclass CountingInputStream extends FilterInputStream { long counter; *(InputStream in) { super(in); } @Override public int read() throws IOException { int c = in.read(); if (c >= 0) ++counter; ret c; } @Override public int read(byte[] b) throws IOException { int n = in.read(b); counter += max(n, 0); ret n; } @Override public int read(byte[] b, int off, int len) throws IOException { int n = in.read(b, off, len); counter += max(n, 0); ret n; } long getFilePointer() { ret counter; } }