@Test public void readOneByteAtATime() throws IOException { final InputStream in = new ThrottledInputStream(Streams.create(this.body), 1000); final long timestampStart = System.nanoTime(); for (int i = 0; i < 100; i++) { in.read(); } final long duration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - timestampStart); final long delta = Math.abs(duration - 100); assertThat(delta, lessThan(15L)); }
@Override public int read() throws IOException { final int b = super.read(); if (b > -1) { throttle(1); } return b; }
ThrottledInputStream extends FilterInputStream { @Override public int read() throws IOException { final int b = super.read(); if (b > -1) { throttle(1); } return b; } }
ThrottledInputStream extends FilterInputStream { @Override public int read() throws IOException { final int b = super.read(); if (b > -1) { throttle(1); } return b; } ThrottledInputStream(final InputStream in, final long bytesPerSecond); }
ThrottledInputStream extends FilterInputStream { @Override public int read() throws IOException { final int b = super.read(); if (b > -1) { throttle(1); } return b; } ThrottledInputStream(final InputStream in, final long bytesPerSecond); @Override int read(); @Override int read(final byte[] b); @Override int read(final byte[] b, final int off, final int len); @Override String toString(); }
ThrottledInputStream extends FilterInputStream { @Override public int read() throws IOException { final int b = super.read(); if (b > -1) { throttle(1); } return b; } ThrottledInputStream(final InputStream in, final long bytesPerSecond); @Override int read(); @Override int read(final byte[] b); @Override int read(final byte[] b, final int off, final int len); @Override String toString();  }