@Override public long copy(final InputStream in, final OutputStream out) throws IOException { return copy(in, out, -1); }
final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class); final Double maxBytesPerSecond = context.getProperty(MAX_DATA_RATE).asDataSize(DataUnit.B); final StreamThrottler streamThrottler = (maxBytesPerSecond == null) ? null : new LeakyBucketStreamThrottler(maxBytesPerSecond.intValue()); final int returnCode = context.getProperty(RETURN_CODE).asInteger(); long requestMaxSize = context.getProperty(MULTIPART_REQUEST_MAX_SIZE).asDataSize(DataUnit.B).longValue();
final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class); final Double maxBytesPerSecond = context.getProperty(MAX_DATA_RATE).asDataSize(DataUnit.B); final StreamThrottler streamThrottler = (maxBytesPerSecond == null) ? null : new LeakyBucketStreamThrottler(maxBytesPerSecond.intValue()); final int returnCode = context.getProperty(RETURN_CODE).asInteger(); long requestMaxSize = context.getProperty(MULTIPART_REQUEST_MAX_SIZE).asDataSize(DataUnit.B).longValue();
@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; }