package com.acdp.transceivr; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; public class CountingInputStream extends FilterInputStream { private int count=0; public CountingInputStream(InputStream is) { super(is); } @Override public int read() throws IOException { int x=super.read(); if(x>0) count++; return x; } @Override public int read(byte[] b) throws IOException { int bytes=super.read(b); count+=bytes; return bytes; } @Override public byte[] readNBytes(int len) throws IOException { byte[] ret= super.readNBytes(len); count+=ret.length; return ret; } @Override public byte[] readAllBytes() throws IOException { byte[] ret= super.readAllBytes(); count+=ret.length; return ret; } @Override public int read(byte[] b, int off, int len) throws IOException { int c= super.read(b, off, len); count+=c; return c; } @Override public int readNBytes(byte[] b, int off, int len) throws IOException { int c= super.readNBytes(b, off, len); count+=c; return c; } public int getCount() { return count; } }