A utility class to convert content from a Content. to an instance
available via a CompletableFuture.
An example usage to asynchronously read UTF-8 content is:
public static class CompletableUTF8String extends ContentSourceCompletableFuture<String>;
{
private final Utf8StringBuilder builder = new Utf8StringBuilder();
public CompletableUTF8String(Content.Source content)
{
super(content);
}
@Override
protected String parse(Content.Chunk chunk) throws Throwable
{
// Accumulate the chunk bytes.
if (chunk.hasRemaining())
builder.append(chunk.getByteBuffer());
// Not the last chunk, the result is not ready yet.
if (!chunk.isLast())
return null;
// The result is ready.
return builder.takeCompleteString(IllegalStateException::new);
}
}
CompletableUTF8String cs = new CompletableUTF8String(source);
cs.parse();
String s = cs.get();
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | Returns: true if the transient failure can be ignored, false otherwiseA transient failure obtained by reading a cause)non-last
failure chunkCallback method that informs the parsing about how to handle transient failures. |
| public void | |
| protected abstract X | Returns: The parsedX result instance or null if parsing is not yet completeThe chunk containing content to parse. The chunk will never be chunknull nor a
failure chunk.
If the chunk is stored away to be used later beyond the scope of this call,
then implementations must call Content. and
Content. as appropriate.Called by |
| _content | back to summary |
|---|---|
| private final Content. | |
| ContentSourceCompletableFuture | back to summary |
|---|---|
| public ContentSourceCompletableFuture(Content. | |
| onTransientFailure | back to summary |
|---|---|
| protected boolean onTransientFailure(Throwable cause) Callback method that informs the parsing about how to handle transient failures.
| |
| parse | back to summary |
|---|---|
| public void parse() Initiates the parsing of the For every valid chunk that is read, Internally, this method is called multiple times to progress
the parsing in response to Exceptions thrown during parsing result in this
| |
| parse | back to summary |
|---|---|
| protected abstract X parse(Content. Called by
| |