/** * Sets the size increment between reporting events. Listeners * are notified if more than numbytes have been written 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 void write(int b) throws IOException { super.write(b); bytes++; doit(); }
public void write(byte[] b, int off, int len) throws IOException { super.write(b,off,len); bytes += Math.min( len, b.length-off); doit(); }
/** * Closes the output stream and notifies all listeners. */ public void close() throws IOException { notifyListeners(); super.close(); }