/** * Sets the size increment between reporting events. Listeners * are notified if more than numbytes have been read from the * stream so far. */ public void setReportSize(int numbytes) { bytes = getByteCount(); blocks = 0; reportSize = numbytes; doit(); // recompute blocks and bytes }
private void doit() { boolean changed = false; while ( bytes >= reportSize ) { long b = bytes/reportSize; blocks += (int) b; bytes -= b*reportSize; changed = true; } if (changed) notifyListeners(); } }
public int read(byte[] buf, int off, int len) throws IOException { int i = super.read(buf,off,len); if ( i != -1 ) { bytes += i; doit(); } return i; }
public int read() throws IOException { int i = super.read(); if ( i != -1 ) { bytes++; doit(); } return i; }
/** * Resets the stream to the position at the last mark. * Listeners will get notified of the change if enough * bytes remain "read". */ public void reset() throws IOException { // un-count the bytes if rewinding occurs if (markpos >= 0 && pos > markpos) { int back = pos - markpos; bytes = getByteCount() - back; blocks = 0; doit(); } super.reset(); }
/** * Closes the input stream and notifies all listeners. */ public void close() throws IOException { notifyListeners(); super.close(); }