public static class ThrottledInputStream.Builder extends AbstractStreamBuilder<T,B>
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. |
ThrottledInputStream.Builder |
setMaxBytes(long value,
java.time.temporal.ChronoUnit chronoUnit)
Sets the maximum bytes per time period unit.
|
void |
setMaxBytesPerSecond(long maxBytesPerSecond)
Sets the maximum bytes per second.
|
getBufferSize, getBufferSizeDefault, getCharSequence, getCharset, getCharsetDefault, getFile, getInputStream, getOpenOptions, getOutputStream, getPath, getRandomAccessFile, getReader, getWriter, setBufferSize, setBufferSize, setBufferSizeChecker, setBufferSizeMax, setCharset, setCharset, setOpenOptionssetByteArray, setCharSequence, setFile, setFile, setInputStream, setOutputStream, setPath, setPath, setRandomAccessFile, setRandomAccessFile, setReader, setURI, setWriterequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitasSupplier, getUncheckedpublic Builder()
ThrottledInputStream.public ThrottledInputStream get() throws java.io.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.java.lang.IllegalStateException - if the origin is null.java.lang.UnsupportedOperationException - if the origin cannot be converted to an InputStream.java.io.IOException - if an I/O error occurs converting to an InputStream using AbstractStreamBuilder.getInputStream().AbstractStreamBuilder.getInputStream(),
IOSupplier.getUnchecked()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.java.lang.IllegalArgumentException - Thrown if maxBytesPerSecond <= 0.public void setMaxBytesPerSecond(long maxBytesPerSecond)
maxBytesPerSecond - the maximum bytes per second.java.lang.IllegalArgumentException - Thrown if maxBytesPerSecond <= 0.Copyright © 2010 - 2025 Adobe. All Rights Reserved