All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.core.util.BufferedFluxByteBuffer Maven / Gradle / Ivy

There is a newer version: 1.54.1
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.util;

import reactor.core.CoreSubscriber;
import reactor.core.publisher.Flux;

import java.nio.ByteBuffer;

/**
 * A {@code Flux} implementation which buffers the contents of the passed {@code Flux} before
 * emitting them downstream.
 */
final class BufferedFluxByteBuffer extends Flux {
    private final Flux flux;

    /**
     * Creates a new instance of {@link BufferedFluxByteBuffer}.
     *
     * @param flux The {@code Flux} to buffer.
     */
    BufferedFluxByteBuffer(Flux flux) {
        this.flux = flux.map(buffer -> {
            ByteBuffer duplicate = ByteBuffer.allocate(buffer.remaining());
            duplicate.put(buffer);
            duplicate.rewind();
            return duplicate;
        }).cache().map(ByteBuffer::duplicate);
    }

    @Override
    public void subscribe(CoreSubscriber actual) {
        flux.subscribe(actual);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy