Use DataBufferUtils.compose and remove writeAggregator

Use DataBufferUtils.compose instead of writeAggregator to combine
multiple data buffers into one, as the write aggregator would not work
when the initial data buffer did not have enough capacity to contain
all subsequent buffers.

Removed writeAggregator, as it is no longer needed.

Issue: SPR-16365
This commit is contained in:
Arjen Poutsma
2018-01-12 10:35:34 +01:00
parent 384a399fd2
commit 67e7c784e8
12 changed files with 20 additions and 50 deletions

View File

@@ -63,8 +63,7 @@ public abstract class AbstractDataBufferDecoder<T> extends AbstractDecoder<T> {
public Mono<T> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType,
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
return Flux.from(inputStream)
.reduce(DataBufferUtils.writeAggregator())
return DataBufferUtils.compose(inputStream)
.map(buffer -> decodeDataBuffer(buffer, elementType, mimeType, hints));
}

View File

@@ -419,22 +419,6 @@ public abstract class DataBufferUtils {
return RELEASE_CONSUMER;
}
/**
* Return an aggregator function that can be used to {@linkplain Flux#reduce(BiFunction) reduce}
* a {@code Flux} of data buffers into a single data buffer by writing all subsequent buffers
* into the first buffer. All buffers except the first buffer are
* {@linkplain #release(DataBuffer) released}.
* <p>For example:
* <pre class="code">
* Flux&lt;DataBuffer&gt; flux = ...
* Mono&lt;DataBuffer&gt; mono = flux.reduce(DataBufferUtils.writeAggregator());
* </pre>
* @see Flux#reduce(BiFunction)
*/
public static BinaryOperator<DataBuffer> writeAggregator() {
return WRITE_AGGREGATOR;
}
/**
* Composes the buffers in the given {@link Publisher} into a single data buffer. Depending on
* the {@code DataBuffer} implementation, the returned buffer may be a single buffer containing