1 7 8 package org.gjt.jclasslib.io; 9 10 import java.io.*; 11 12 18 public class CountedInputStream extends FilterInputStream { 19 20 private int bytesRead = 0; 21 22 26 public CountedInputStream(InputStream in) { 27 super(in); 28 } 29 30 public int read() throws IOException { 31 int b = in.read(); 32 bytesRead++; 34 return b; 36 } 37 38 public int read(byte[] b) throws IOException { 39 return read(b, 0, b.length); 40 } 41 42 public int read(byte[] b, int offset, int len) throws IOException { 43 int readCount = in.read(b, 0, b.length); 44 bytesRead += readCount; 45 return readCount; 46 47 } 48 49 public long skip(long n) throws IOException { 50 long skipCount = in.skip(n); 51 bytesRead += (int)skipCount; 52 return skipCount; 53 } 54 55 public boolean markSupported() { 57 return false; 58 } 59 60 64 public int getBytesRead() { 65 return bytesRead; 66 } 67 } 68 | Popular Tags |