Search in sources :

Example 1 with PooledDataBuffer

use of cn.taketoday.core.io.buffer.PooledDataBuffer 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));
}
Also used : DataBufferUtils(cn.taketoday.core.io.buffer.DataBufferUtils) LimitedDataBufferList(cn.taketoday.core.io.buffer.LimitedDataBufferList) PooledDataBuffer(cn.taketoday.core.io.buffer.PooledDataBuffer) PooledDataBuffer(cn.taketoday.core.io.buffer.PooledDataBuffer) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer)

Example 2 with PooledDataBuffer

use of cn.taketoday.core.io.buffer.PooledDataBuffer 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));
}
Also used : DataBufferUtils(cn.taketoday.core.io.buffer.DataBufferUtils) LimitedDataBufferList(cn.taketoday.core.io.buffer.LimitedDataBufferList) PooledDataBuffer(cn.taketoday.core.io.buffer.PooledDataBuffer) PooledDataBuffer(cn.taketoday.core.io.buffer.PooledDataBuffer) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer)

Aggregations

DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)2 DataBufferUtils (cn.taketoday.core.io.buffer.DataBufferUtils)2 LimitedDataBufferList (cn.taketoday.core.io.buffer.LimitedDataBufferList)2 PooledDataBuffer (cn.taketoday.core.io.buffer.PooledDataBuffer)2