jetty / jetty/jetty.project

Introduce common logic for Content.Source iterating over all chunks

Open
#11,758 2 comments 0 reactions 1 assignee Claimed by @lorban View on GitHub
Enhancement
Dominant language
Java
Stars
4.1k
Forks
2k
Avg merge
3d 56m
Merged PRs (30d)
48

Description

**Jetty version(s)**
12.0.8

**Enhancement Description**

Currently there are number of implementations that are doing the same thing: iterate over all chunks in Content.Source and make some transformation. Below the table with all those implementations

```
ByteBuffer asByteBuffer(Source source) ContentSourceByteBuffer
void asByteBuffer(Source source, Promise promise) ContentSourceByteBuffer
CompletableFuture asByteBufferAsync(Source source) ChunkAccumulator
CompletableFuture asByteBufferAsync(Source source, int maxSize) ChunkAccumulator

CompletableFuture asByteArrayAsync(Source source, int maxSize) ChunkAccumulator

CompletableFuture asRetainableByteBuffer(Source source, ByteBufferPool pool, boolean direct, int maxSize) ChunkAccumulator

String asString(Source source) ContentSourceString
String asString(Source source, Charset charset) ContentSourceString
void asString(Source source, Charset charset, Promise promise) ContentSourceString
CompletableFuture asStringAsync(Source source, Charset charset) ContentSourceString

InputStream asInputStream(Source source) ContentSourceInputStream

Flow.Publisher asPublisher(Source source) ContentSourcePublisher

void consumeAll(Source source) ContentSourceConsumer
void consumeAll(Source source, Callback callback) ContentSourceConsumer
```

That may lead to the inconsistent behavior and multiplies surface of mistakes (for example ChunkAccumulator has a bug while ContentSourceByteBuffer don't have such bug https://github.com/jetty/jetty.project/issues/11756)

What do you think if it good idea to implement Content.Source iterating via Flow.Publisher as a reference and all other implementations will use it and just process chunks differently? It should also cover that issue https://github.com/jetty/jetty.project/issues/11755

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.