/** * Wraps the input stream to emulate a slow device * @param in input stream * @param cps characters per second to emulate */ public SlowInputStream(InputStream in, int cps) { super(in); pauser = new CPSPauser(cps); }
@Override public int read() throws IOException { pauser.pause(1); return in.read(); }
@Override public void write(byte[] b, int off, int len) throws IOException { pauser.pause(len); out.write(b, off, len); }
@Override public void write(int b) throws IOException { pauser.pause(1); out.write(b); } }
/** * Create wrapped Output Stream toe emulate the requested CPS. * @param out OutputStream * @param cps characters per second */ public SlowOutputStream(OutputStream out, int cps) { super(out); pauser = new CPSPauser(cps); }
@Override public int read(byte[] b, int off, int len) throws IOException { pauser.pause(len); return in.read(b, off, len); }