public static class BoundedInputStream.Builder extends AbstractStreamBuilder<T,B>
BoundedInputStream.
By default, a BoundedInputStream is unbound; so make sure to call AbstractBuilder#setMaxCount(long).
You can find out how many bytes this stream has seen so far by calling BoundedInputStream.getCount(). This value reflects bytes read and skipped.
A ServletInputStream can block if you try to read content that isn't there
because it doesn't know whether the content hasn't arrived yet or whether the content has finished. Initialize an BoundedInputStream with the
Content-Length sent in the ServletInputStream's header, this stop it from blocking, providing it's been sent with a correct content
length in the first place.
BoundedInputStream s = BoundedInputStream.builder()
.setPath(Paths.get("MyFile.xml"))
.setMaxCount(1024)
.setPropagateClose(false)
.get();
BoundedInputStream s = BoundedInputStream.builder()
.setFile(new File("MyFile.xml"))
.setMaxCount(1024)
.setPropagateClose(false)
.get();
You can set the running count when building, which is most useful when starting from another stream:
InputStream in = ...;
BoundedInputStream s = BoundedInputStream.builder()
.setInputStream(in)
.setCount(12)
.setMaxCount(1024)
.setPropagateClose(false)
.get();
get()| Constructor and Description |
|---|
Builder()
Constructs a new builder of
BoundedInputStream. |
| Modifier and Type | Method and Description |
|---|---|
BoundedInputStream |
get()
Builds a new
BoundedInputStream. |
T |
setCount(long count)
Sets the current number of bytes counted.
|
T |
setMaxCount(long maxCount)
Sets the maximum number of bytes to return.
|
T |
setOnMaxCount(IOBiConsumer<java.lang.Long,java.lang.Long> onMaxCount)
Sets the default
BoundedInputStream.onMaxLength(long, long) behavior, null resets to a NOOP. |
T |
setPropagateClose(boolean propagateClose)
Sets whether the
ProxyInputStream.close() method should propagate to the underling InputStream. |
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()
BoundedInputStream.public BoundedInputStream get() throws java.io.IOException
BoundedInputStream.
You must set an aspect that supports AbstractStreamBuilder.getInputStream(), otherwise, this method throws an exception.
If you start from an input stream, an exception can't be thrown, and you can call IOSupplier.getUnchecked() instead.
This builder uses the following aspects:
AbstractStreamBuilder.getInputStream() gets the target aspect.getAfterRead()getCount()getMaxCount()getOnMaxCount()isPropagateClose()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 T setCount(long count)
Useful when building from another stream to carry forward a read count.
Default is 0, negative means 0.
count - The current number of bytes counted.this instance.public T setMaxCount(long maxCount)
Default is , negative means unbound.
maxCount - The maximum number of bytes to return, negative means unbound.this instance.public T setOnMaxCount(IOBiConsumer<java.lang.Long,java.lang.Long> onMaxCount)
BoundedInputStream.onMaxLength(long, long) behavior, null resets to a NOOP.
The first Long is the max count of bytes to read. The second Long is the count of bytes read.
This does not override a BoundedInputStream subclass' implementation of the BoundedInputStream.onMaxLength(long, long)
method.
onMaxCount - the ProxyInputStream.afterRead(int) behavior.public T setPropagateClose(boolean propagateClose)
ProxyInputStream.close() method should propagate to the underling InputStream.
Default is true.
propagateClose - true if calling ProxyInputStream.close() propagates to the close() method of the underlying stream or false if
it does not.this instance.Copyright © 2010 - 2025 Adobe. All Rights Reserved