public static class ThrottledInputStream.Builder extends ProxyInputStream.AbstractBuilder<ThrottledInputStream,ThrottledInputStream.Builder>
ThrottledInputStream.
ThrottledInputStream in = ThrottledInputStream.builder()
.setPath(Paths.get("MyFile.xml"))
.setMaxBytes(100_000, ChronoUnit.SECONDS)
.get();
ThrottledInputStream in = ThrottledInputStream.builder()
.setFile(new File("MyFile.xml"))
.setMaxBytes(100_000, ChronoUnit.SECONDS)
.get();
ThrottledInputStream in = ThrottledInputStream.builder()
.setInputStream(inputStream)
.setMaxBytes(100_000, ChronoUnit.SECONDS)
.get();
get()| Constructor and Description |
|---|
Builder()
Constructs a new builder of
ThrottledInputStream. |
| Modifier and Type | Method and Description |
|---|---|
ThrottledInputStream |
get()
Builds a new
ThrottledInputStream. |
(package private) double |
getMaxBytesPerSecond() |
ThrottledInputStream.Builder |
setMaxBytes(long value,
java.time.temporal.ChronoUnit chronoUnit)
Sets the maximum bytes per time period unit.
|
(package private) ThrottledInputStream.Builder |
setMaxBytes(long value,
java.time.Duration duration)
Sets the maximum bytes per duration.
|
void |
setMaxBytesPerSecond(long maxBytesPerSecond)
Sets the maximum bytes per second.
|
getAfterRead, setAfterReadgetBufferSize, getBufferSizeDefault, getCharSequence, getCharset, getCharsetDefault, getFile, getInputStream, getOpenOptions, getOutputStream, getPath, getRandomAccessFile, getReader, getWriter, setBufferSize, setBufferSize, setBufferSizeChecker, setBufferSizeDefault, setBufferSizeMax, setCharset, setCharset, setCharsetDefault, setOpenOptionscheckOrigin, getOrigin, hasOrigin, newByteArrayOrigin, newCharSequenceOrigin, newFileOrigin, newFileOrigin, newInputStreamOrigin, newOutputStreamOrigin, newPathOrigin, newPathOrigin, newRandomAccessFileOrigin, newRandomAccessFileOrigin, newReaderOrigin, newURIOrigin, newWriterOrigin, setByteArray, setCharSequence, setFile, setFile, setInputStream, setOrigin, setOutputStream, setPath, setPath, setRandomAccessFile, setRandomAccessFile, setReader, setURI, setWriterasThisclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitasSupplier, getUncheckedpublic Builder()
ThrottledInputStream.public ThrottledInputStream get() throws IOException
ThrottledInputStream.
You must set an aspect that supports AbstractStreamBuilder.getInputStream(), otherwise, this method throws an exception.
This builder uses the following aspects:
AbstractStreamBuilder.getInputStream() gets the target aspect.IllegalStateException - if the origin is null.UnsupportedOperationException - if the origin cannot be converted to an InputStream.IOException - if an I/O error occurs converting to an InputStream using AbstractStreamBuilder.getInputStream().AbstractStreamBuilder.getInputStream(),
IOSupplier.getUnchecked()double getMaxBytesPerSecond()
public ThrottledInputStream.Builder setMaxBytes(long value, java.time.temporal.ChronoUnit chronoUnit)
For example, to throttle reading to 100K per second, use:
builder.setMaxBytes(100_000, ChronoUnit.SECONDS)
To test idle timeouts for example, use 1 byte per minute, 1 byte per 30 seconds, and so on.
value - the maximum byteschronoUnit - a duration scale goal.IllegalArgumentException - Thrown if maxBytesPerSecond <= 0.ThrottledInputStream.Builder setMaxBytes(long value, java.time.Duration duration)
For example, to throttle reading to 100K per second, use:
builder.setMaxBytes(100_000, Duration.ofSeconds(1))
To test idle timeouts for example, use 1 byte per minute, 1 byte per 30 seconds, and so on.
value - the maximum bytesduration - a duration goal.IllegalArgumentException - Thrown if maxBytesPerSecond <= 0.public void setMaxBytesPerSecond(long maxBytesPerSecond)
maxBytesPerSecond - the maximum bytes per second.IllegalArgumentException - Thrown if maxBytesPerSecond <= 0.