public static class BoundedInputStream.Builder extends BoundedInputStream.AbstractBuilder<BoundedInputStream.Builder>
BoundedInputStream.
By default, a BoundedInputStream is unbound; so make sure to call BoundedInputStream.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() |
| Modifier and Type | Method and Description |
|---|---|
BoundedInputStream |
get()
Builds a new
BoundedInputStream. |
getCount, getMaxCount, isPropagateClose, setCount, setMaxCount, setPropagateClosegetBufferSize, getBufferSizeDefault, getCharSequence, getCharset, getCharsetDefault, getInputStream, getOpenOptions, getOutputStream, getPath, getReader, getWriter, setBufferSize, setBufferSize, setBufferSizeChecker, setBufferSizeDefault, setBufferSizeMax, setCharset, setCharset, setCharsetDefault, setOpenOptionscheckOrigin, getOrigin, hasOrigin, newByteArrayOrigin, newCharSequenceOrigin, newFileOrigin, newFileOrigin, newInputStreamOrigin, newOutputStreamOrigin, newPathOrigin, newPathOrigin, newReaderOrigin, newURIOrigin, newWriterOrigin, setByteArray, setCharSequence, setFile, setFile, setInputStream, setOrigin, setOutputStream, setPath, setPath, setReader, setURI, setWriterasThisclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitasSupplierpublic BoundedInputStream get() throws java.io.IOException
BoundedInputStream.
You must set input that supports AbstractStreamBuilder.getInputStream(), otherwise, this method throws an exception.
This builder use the following aspects:
AbstractStreamBuilder.getInputStream()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.AbstractStreamBuilder.getInputStream()