@Override public long copy(final InputStream in, final OutputStream out) throws IOException { return copy(in, out, -1); }
@Override public void write(byte[] b, int off, int len) throws IOException { final InputStream in = new ByteArrayInputStream(b, off, len); LeakyBucketStreamThrottler.this.copy(in, toWrap); }
@Override public int read() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(1); LeakyBucketStreamThrottler.this.copy(toWrap, baos, 1L); if (baos.size() < 1) { return -1; } return baos.toByteArray()[0] & 0xFF; }
@Override public int read(byte[] b, int off, int len) throws IOException { if (len < 0) { throw new IllegalArgumentException(); } if (len == 0) { return 0; } baos.reset(); final int copied = (int) LeakyBucketStreamThrottler.this.copy(toWrap, baos, len); if (copied == 0) { return -1; } System.arraycopy(baos.toByteArray(), 0, b, off, copied); return copied; }
@Override public long copy(final InputStream in, final OutputStream out) throws IOException { return copy(in, out, -1); }
@Override public void write(byte[] b, int off, int len) throws IOException { final InputStream in = new ByteArrayInputStream(b, off, len); LeakyBucketStreamThrottler.this.copy(in, toWrap); }
@Override public int read() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(1); LeakyBucketStreamThrottler.this.copy(toWrap, baos, 1L); if (baos.size() < 1) { return -1; } return baos.toByteArray()[0] & 0xFF; }
@Override public int read(byte[] b, int off, int len) throws IOException { if (len < 0) { throw new IllegalArgumentException(); } if (len == 0) { return 0; } baos.reset(); final int copied = (int) LeakyBucketStreamThrottler.this.copy(toWrap, baos, len); if (copied == 0) { return -1; } System.arraycopy(baos.toByteArray(), 0, b, off, copied); return copied; }