public static final class CapturingReader.Config.Builder extends Object
capturing reader configurations
.Modifier and Type | Method and Description |
---|---|
CapturingReader.Config |
build()
Creates a new
capturing reader configuration with the settings from this builder. |
CapturingReader.Config.Builder |
doneAfter(long count)
Sets the number of characters after which built capturing readers are considered to be done.
|
CapturingReader.Config.Builder |
onDone(Consumer<? super CapturingReader> callback)
Sets a callback that will be triggered when reading from built capturing readers is done.
|
CapturingReader.Config.Builder |
onError(BiConsumer<? super CapturingReader,? super IOException> callback)
Sets a callback that will be triggered when an
IOException occurs while using built capturing readers. |
CapturingReader.Config.Builder |
onLimitReached(Consumer<? super CapturingReader> callback)
Sets a callback that will be triggered when built capturing readers hit their limit.
|
CapturingReader.Config.Builder |
withExpectedCount(int expectedCount)
Sets the expected number of characters that can be read from the wrapped reader.
|
CapturingReader.Config.Builder |
withLimit(int limit)
Sets the maximum number of characters to capture.
|
public CapturingReader.Config.Builder withLimit(int limit)
Integer.MAX_VALUE
.limit
- The maximum number of characters to capture.IllegalArgumentException
- If the given limit is negative.public CapturingReader.Config.Builder withExpectedCount(int expectedCount)
-1
.expectedCount
- The expected number of characters that can be read from the wrapped reader, or a negative number if not known.public CapturingReader.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 characters after which to consider built capturing readers as done.IllegalArgumentException
- If the given number of characters is negative.public CapturingReader.Config.Builder onDone(Consumer<? super CapturingReader> callback)
consumed
or closed
, or because the amount set using
doneAfter(long)
has been reached.
A capturing reader will only trigger its callback once.callback
- The callback to set.NullPointerException
- If the given callback is null
.public CapturingReader.Config.Builder onLimitReached(Consumer<? super CapturingReader> callback)
In case a capturing reader has reached its limit and is then CapturingReader.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 CapturingReader.Config.Builder onError(BiConsumer<? super CapturingReader,? super IOException> callback)
IOException
occurs while using built capturing readers.
A capturing reader can trigger its error callback multiple times.callback
- The callback to set.NullPointerException
- If the given callback is null
.public CapturingReader.Config build()
capturing reader configuration
with the settings from this builder.Copyright © 2020–2024. All rights reserved.