public static final class CapturingInputStream.Config.Builder extends Object
capturing input stream configurations
.Modifier and Type | Method and Description |
---|---|
CapturingInputStream.Config |
build()
Creates a new
capturing input stream configuration with the settings from this builder. |
CapturingInputStream.Config.Builder |
doneAfter(long count)
Sets the number of bytes after which built capturing input streams are considered to be done.
|
CapturingInputStream.Config.Builder |
onDone(Consumer<? super CapturingInputStream> callback)
Sets a callback that will be triggered when reading from built capturing input streams is done.
|
CapturingInputStream.Config.Builder |
onError(BiConsumer<? super CapturingInputStream,? super IOException> callback)
Sets a callback that will be triggered when an
IOException occurs while using built capturing input streams. |
CapturingInputStream.Config.Builder |
onLimitReached(Consumer<? super CapturingInputStream> callback)
Sets a callback that will be triggered when built capturing input streams hit their limit.
|
CapturingInputStream.Config.Builder |
withExpectedCount(int expectedCount)
Sets the expected number of bytes that can be read from the wrapped input stream.
|
CapturingInputStream.Config.Builder |
withLimit(int limit)
Sets the maximum number of bytes to capture.
|
public CapturingInputStream.Config.Builder withLimit(int limit)
Integer.MAX_VALUE
.limit
- The maximum number of bytes to capture.IllegalArgumentException
- If the given limit is negative.public CapturingInputStream.Config.Builder withExpectedCount(int expectedCount)
-1
.expectedCount
- The expected number of bytes that can be read from the wrapped input stream, or a negative number if not known.public CapturingInputStream.Config.Builder doneAfter(long count)
Long.MAX_VALUE
.
Some frameworks don't fully consume all content. Instead they stop at a specific point. For instance, some JSON parsers stop reading as soon as the root object's closing closing curly brace is encountered.
Ideally such a framework is configured to consume all content. This method can be used as fallback if that's not possible. For instance, it can be called with an HTTP request's content length.
count
- The number of bytes after which to consider built capturing input streams as done.IllegalArgumentException
- If the given number of bytes is negative.public CapturingInputStream.Config.Builder onDone(Consumer<? super CapturingInputStream> callback)
consumed
or closed
, or because the amount set using
doneAfter(long)
has been reached.
A capturing input stream will only trigger its callback once.callback
- The callback to set.NullPointerException
- If the given callback is null
.public CapturingInputStream.Config.Builder onLimitReached(Consumer<? super CapturingInputStream> callback)
In case a capturing input stream has reached its limit and is then CapturingInputStream.reset()
to before its limit, it will
not call its callback again.
callback
- The callback to set.NullPointerException
- If the given callback is null
.public CapturingInputStream.Config.Builder onError(BiConsumer<? super CapturingInputStream,? super IOException> callback)
IOException
occurs while using built capturing input streams.
A capturing input stream can trigger its error callback multiple times.callback
- The callback to set.NullPointerException
- If the given callback is null
.public CapturingInputStream.Config build()
capturing input stream configuration
with the settings from this builder.Copyright © 2020–2024. All rights reserved.