Search in sources :

Example 1 with PooledDataBuffer

use of org.springframework.core.io.buffer.PooledDataBuffer in project spring-framework by spring-projects.

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).map(buffer -> decode(buffer, elementType, mimeType, hints));
}
Also used : DataBufferUtils(org.springframework.core.io.buffer.DataBufferUtils) LimitedDataBufferList(org.springframework.core.io.buffer.LimitedDataBufferList) PooledDataBuffer(org.springframework.core.io.buffer.PooledDataBuffer) PooledDataBuffer(org.springframework.core.io.buffer.PooledDataBuffer) DataBuffer(org.springframework.core.io.buffer.DataBuffer)

Aggregations

DataBuffer (org.springframework.core.io.buffer.DataBuffer)1 DataBufferUtils (org.springframework.core.io.buffer.DataBufferUtils)1 LimitedDataBufferList (org.springframework.core.io.buffer.LimitedDataBufferList)1 PooledDataBuffer (org.springframework.core.io.buffer.PooledDataBuffer)1