com.azure.core.util.BufferedFluxByteBuffer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-core Show documentation
Show all versions of azure-core Show documentation
This package contains core types for Azure Java clients.
// 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 super ByteBuffer> actual) {
flux.subscribe(actual);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy