sclass CountingOutputStream extends FilterOutputStream { long counter; *(OutputStream out) { super(out); } @Override public void write(int b) throws IOException { ++counter; out.write(b); } @Override public void write(byte[] b) throws IOException { counter += b.length; out.write(b, 0, b.length); } @Override public void write(byte[] b, int off, int len) throws IOException { if (len == 0) ret; counter += len; out.write(b, off, len); } long getFilePointer() { ret counter; } }