use of cn.taketoday.core.io.buffer.LimitedDataBufferList in project today-infrastructure by TAKETODAY.
the class StringDecoder method decode.
@Override
public Flux<String> decode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
byte[][] delimiterBytes = getDelimiterBytes(mimeType);
LimitedDataBufferList chunks = new LimitedDataBufferList(getMaxInMemorySize());
DataBufferUtils.Matcher matcher = DataBufferUtils.matcher(delimiterBytes);
return Flux.from(input).concatMapIterable(buffer -> processDataBuffer(buffer, matcher, chunks)).concatWith(Mono.defer(() -> {
if (chunks.isEmpty()) {
return Mono.empty();
}
DataBuffer lastBuffer = chunks.get(0).factory().join(chunks);
chunks.clear();
return Mono.just(lastBuffer);
})).doOnTerminate(chunks::releaseAndClear).doOnDiscard(PooledDataBuffer.class, PooledDataBuffer::release).mapNotNull(buffer -> decode(buffer, elementType, mimeType, hints));
}
use of cn.taketoday.core.io.buffer.LimitedDataBufferList in project today-framework by TAKETODAY.
the class StringDecoder method decode.
@Override
public Flux<String> decode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
byte[][] delimiterBytes = getDelimiterBytes(mimeType);
LimitedDataBufferList chunks = new LimitedDataBufferList(getMaxInMemorySize());
DataBufferUtils.Matcher matcher = DataBufferUtils.matcher(delimiterBytes);
return Flux.from(input).concatMapIterable(buffer -> processDataBuffer(buffer, matcher, chunks)).concatWith(Mono.defer(() -> {
if (chunks.isEmpty()) {
return Mono.empty();
}
DataBuffer lastBuffer = chunks.get(0).factory().join(chunks);
chunks.clear();
return Mono.just(lastBuffer);
})).doOnTerminate(chunks::releaseAndClear).doOnDiscard(PooledDataBuffer.class, PooledDataBuffer::release).mapNotNull(buffer -> decode(buffer, elementType, mimeType, hints));
}
Aggregations