package cs522.elind.io; import java.io.*; public class MonitorObjectInputStream extends ObjectInputStream { protected ObjectInputStream monitor = null; protected long totalRead = 0; public MonitorObjectInputStream(ObjectInputStream in) throws IOException { monitor = in; } public long bytesRead() { return totalRead; } public int read() throws IOException { int read = monitor.read(); if(read != -1) { totalRead += read; } return read; } public int read(byte[] b) throws IOException { int read = monitor.read(b); if(read != -1) { totalRead += read; } return read; } public int read(byte[] b, int off, int len) throws IOException { int read = monitor.read(b, off, len); if(read != -1) { totalRead += read; } return read; } public long skip(long n) throws IOException { long read = monitor.skip(n); totalRead += read; return read; } public int available() throws IOException { return monitor.available(); } public void close() throws IOException { monitor.close(); } public void mark(int readlimit) { monitor.mark(readlimit); } public void reset() throws IOException { monitor.reset(); } public boolean markSupported() { return monitor.markSupported(); } }