Modifier and Type | Method and Description |
---|---|
static byte[] |
byteBufferToArray(ByteBuffer byteBuffer)
Gets the content of the provided ByteBuffer as a byte array.
|
static Mono<byte[]> |
collectBytesFromNetworkResponse(Flux<ByteBuffer> stream,
HttpHeaders headers)
Collects ByteBuffers returned in a network response into a byte array.
|
static Mono<byte[]> |
collectBytesInByteBufferStream(Flux<ByteBuffer> stream)
Collects ByteBuffers emitted by a Flux into a byte array.
|
static Mono<byte[]> |
collectBytesInByteBufferStream(Flux<ByteBuffer> stream,
int sizeHint)
Collects ByteBuffers emitted by a Flux into a byte array.
|
static Flux<ByteBuffer> |
createRetriableDownloadFlux(Supplier<Flux<ByteBuffer>> downloadSupplier,
BiFunction<Throwable,Long,Flux<ByteBuffer>> onDownloadErrorResume,
int maxRetries)
Creates a
Flux that is capable of resuming a download by applying retry logic when an error occurs. |
static Flux<ByteBuffer> |
createRetriableDownloadFlux(Supplier<Flux<ByteBuffer>> downloadSupplier,
BiFunction<Throwable,Long,Flux<ByteBuffer>> onDownloadErrorResume,
int maxRetries,
long position)
Creates a
Flux that is capable of resuming a download by applying retry logic when an error occurs. |
static <T> Flux<T> |
fluxContext(Function<Context,Flux<T>> serviceCall)
This method converts the incoming
deferContextual from Reactor
Context to Azure Context and calls the given lambda function with this context and returns a
collection of type T |
static <T> Flux<T> |
fluxError(ClientLogger logger,
RuntimeException ex)
Propagates a
RuntimeException through the error channel of Flux . |
static boolean |
isFluxByteBuffer(Type entityType)
Checks if a type is Flux<ByteBuffer>.
|
static <T> Mono<T> |
monoError(ClientLogger logger,
RuntimeException ex)
Propagates a
RuntimeException through the error channel of Mono . |
static <T> PagedFlux<T> |
pagedFluxError(ClientLogger logger,
RuntimeException ex)
Propagates a
RuntimeException through the error channel of PagedFlux . |
static Flux<ByteBuffer> |
readFile(AsynchronousFileChannel fileChannel)
Creates a
Flux from an AsynchronousFileChannel which reads the entire file. |
static Flux<ByteBuffer> |
readFile(AsynchronousFileChannel fileChannel,
int chunkSize,
long offset,
long length)
Creates a
Flux from an AsynchronousFileChannel which reads part of a file into chunks of the
given size. |
static Flux<ByteBuffer> |
readFile(AsynchronousFileChannel fileChannel,
long offset,
long length)
Creates a
Flux from an AsynchronousFileChannel which reads part of a file. |
static Flux<ByteBuffer> |
toFluxByteBuffer(InputStream inputStream)
|
static Flux<ByteBuffer> |
toFluxByteBuffer(InputStream inputStream,
int chunkSize)
|
static <T> Mono<T> |
toMono(Response<T> response)
Converts the incoming content to Mono.
|
static Context |
toReactorContext(Context context)
Converts an Azure context to Reactor context.
|
static <T> Mono<T> |
withContext(Function<Context,Mono<T>> serviceCall)
This method converts the incoming
deferContextual from Reactor
Context to Azure Context and calls the given lambda function with this context and returns a
single entity of type T |
static <T> Mono<T> |
withContext(Function<Context,Mono<T>> serviceCall,
Map<String,String> contextAttributes)
This method converts the incoming
deferContextual from Reactor
Context to Azure Context , adds the specified context attributes and calls the given lambda
function with this context and returns a single entity of type T |
static Mono<Void> |
writeFile(Flux<ByteBuffer> content,
AsynchronousFileChannel outFile)
|
static Mono<Void> |
writeFile(Flux<ByteBuffer> content,
AsynchronousFileChannel outFile,
long position)
Writes the
ByteBuffers emitted by a Flux of ByteBuffer to an AsynchronousFileChannel starting at the given position in the file. |
public static boolean isFluxByteBuffer(Type entityType)
entityType
- the type to checkpublic static Mono<byte[]> collectBytesInByteBufferStream(Flux<ByteBuffer> stream)
stream
- A stream which emits ByteBuffer instances.IllegalStateException
- If the combined size of the emitted ByteBuffers is greater than Integer.MAX_VALUE
.public static Mono<byte[]> collectBytesInByteBufferStream(Flux<ByteBuffer> stream, int sizeHint)
Unlike FluxUtil.collectBytesInByteBufferStream(Flux)
, this method accepts a second parameter sizeHint
.
This size hint allows for optimizations when creating the initial buffer to reduce the number of times it needs
to be resized while concatenating emitted ByteBuffers.
stream
- A stream which emits ByteBuffer instances.sizeHint
- A hint about the expected stream size.IllegalArgumentException
- If sizeHint
is equal to or less than 0
.IllegalStateException
- If the combined size of the emitted ByteBuffers is greater than Integer.MAX_VALUE
.public static Mono<byte[]> collectBytesFromNetworkResponse(Flux<ByteBuffer> stream, HttpHeaders headers)
The headers
are inspected for containing an Content-Length
which determines if a size hinted
collection, FluxUtil.collectBytesInByteBufferStream(Flux, int)
, or default collection, FluxUtil.collectBytesInByteBufferStream(Flux)
, will be used.
stream
- A network response ByteBuffer stream.headers
- The HTTP headers of the response.NullPointerException
- If headers
is null.IllegalStateException
- If the size of the network response is greater than Integer.MAX_VALUE
.public static byte[] byteBufferToArray(ByteBuffer byteBuffer)
byteBuffer
- the byte bufferpublic static Flux<ByteBuffer> createRetriableDownloadFlux(Supplier<Flux<ByteBuffer>> downloadSupplier, BiFunction<Throwable,Long,Flux<ByteBuffer>> onDownloadErrorResume, int maxRetries)
Flux
that is capable of resuming a download by applying retry logic when an error occurs.downloadSupplier
- Supplier of the initial download.onDownloadErrorResume
- BiFunction
of Throwable
and Long
which is used to resume
downloading when an error occurs.maxRetries
- The maximum number of times a download can be resumed when an error occurs.Flux
that downloads reliably.public static Flux<ByteBuffer> createRetriableDownloadFlux(Supplier<Flux<ByteBuffer>> downloadSupplier, BiFunction<Throwable,Long,Flux<ByteBuffer>> onDownloadErrorResume, int maxRetries, long position)
Flux
that is capable of resuming a download by applying retry logic when an error occurs.downloadSupplier
- Supplier of the initial download.onDownloadErrorResume
- BiFunction
of Throwable
and Long
which is used to resume
downloading when an error occurs.maxRetries
- The maximum number of times a download can be resumed when an error occurs.position
- The initial offset for the download.Flux
that downloads reliably.public static Flux<ByteBuffer> toFluxByteBuffer(InputStream inputStream)
InputStream
into a Flux
of ByteBuffer
using a chunk size of 4096.
Given that InputStream
is not guaranteed to be replayable the returned Flux
should be considered
non-replayable as well.
If the passed InputStream
is null
Flux.empty()
will be returned.
inputStream
- The InputStream
to convert into a Flux
.Flux
of ByteBuffers
that contains the contents of the stream.public static Flux<ByteBuffer> toFluxByteBuffer(InputStream inputStream, int chunkSize)
InputStream
into a Flux
of ByteBuffer
.
Given that InputStream
is not guaranteed to be replayable the returned Flux
should be considered
non-replayable as well.
If the passed InputStream
is null
Flux.empty()
will be returned.
inputStream
- The InputStream
to convert into a Flux
.chunkSize
- The requested size for each ByteBuffer
.Flux
of ByteBuffers
that contains the contents of the stream.IllegalArgumentException
- If chunkSize
is less than or equal to 0
.public static <T> Mono<T> withContext(Function<Context,Mono<T>> serviceCall)
deferContextual
from Reactor
Context
to Azure Context
and calls the given lambda function with this context and returns a
single entity of type T
If the reactor context is empty, Context.NONE
will be used to call the lambda function
Code samples
String prefix = "Hello, "; Mono<String> response = FluxUtil .withContext(context -> serviceCallReturnsSingle(prefix, context));
T
- The type of response returned from the service callserviceCall
- The lambda function that makes the service call into which azure context will be passedpublic static <T> Mono<T> withContext(Function<Context,Mono<T>> serviceCall, Map<String,String> contextAttributes)
deferContextual
from Reactor
Context
to Azure Context
, adds the specified context attributes and calls the given lambda
function with this context and returns a single entity of type T
If the reactor context is empty, Context.NONE
will be used to call the lambda function
T
- The type of response returned from the service callserviceCall
- serviceCall The lambda function that makes the service call into which azure context will be
passedcontextAttributes
- The map of attributes sent by the calling method to be set on Context
.public static <T> Mono<T> toMono(Response<T> response)
public static <T> Mono<T> monoError(ClientLogger logger, RuntimeException ex)
RuntimeException
through the error channel of Mono
.T
- The return type.logger
- The ClientLogger
to log the exception.ex
- The RuntimeException
.Mono
that terminates with error wrapping the RuntimeException
.public static <T> Flux<T> fluxError(ClientLogger logger, RuntimeException ex)
RuntimeException
through the error channel of Flux
.T
- The return type.logger
- The ClientLogger
to log the exception.ex
- The RuntimeException
.Flux
that terminates with error wrapping the RuntimeException
.public static <T> PagedFlux<T> pagedFluxError(ClientLogger logger, RuntimeException ex)
RuntimeException
through the error channel of PagedFlux
.T
- The return type.logger
- The ClientLogger
to log the exception.ex
- The RuntimeException
.PagedFlux
that terminates with error wrapping the RuntimeException
.public static <T> Flux<T> fluxContext(Function<Context,Flux<T>> serviceCall)
deferContextual
from Reactor
Context
to Azure Context
and calls the given lambda function with this context and returns a
collection of type T
If the reactor context is empty, Context.NONE
will be used to call the lambda function
Code samples
String prefix = "Hello, "; Flux<String> response = FluxUtil .fluxContext(context -> serviceCallReturnsCollection(prefix, context));
T
- The type of response returned from the service callserviceCall
- The lambda function that makes the service call into which the context will be passedpublic static Context toReactorContext(Context context)
null
or empty, Context.empty()
will be returned.context
- The Azure context.public static Mono<Void> writeFile(Flux<ByteBuffer> content, AsynchronousFileChannel outFile)
ByteBuffers
emitted by a Flux
of ByteBuffer
to an AsynchronousFileChannel
.
The outFile
is not closed by this call, closing of the outFile
is managed by the caller.
The response Mono
will emit an error if content
or outFile
are null. Additionally, an
error will be emitted if the outFile
wasn't opened with the proper open options, such as StandardOpenOption.WRITE
.
content
- The Flux
of ByteBuffer
content.outFile
- The AsynchronousFileChannel
.Mono
which emits a completion status once the Flux
has been written to the AsynchronousFileChannel
.public static Mono<Void> writeFile(Flux<ByteBuffer> content, AsynchronousFileChannel outFile, long position)
ByteBuffers
emitted by a Flux
of ByteBuffer
to an AsynchronousFileChannel
starting at the given position
in the file.
The outFile
is not closed by this call, closing of the outFile
is managed by the caller.
The response Mono
will emit an error if content
or outFile
are null or position
is less than 0. Additionally, an error will be emitted if the outFile
wasn't opened with the proper open
options, such as StandardOpenOption.WRITE
.
content
- The Flux
of ByteBuffer
content.outFile
- The AsynchronousFileChannel
.position
- The position in the file to begin writing the content
.Mono
which emits a completion status once the Flux
has been written to the AsynchronousFileChannel
.public static Flux<ByteBuffer> readFile(AsynchronousFileChannel fileChannel, int chunkSize, long offset, long length)
Flux
from an AsynchronousFileChannel
which reads part of a file into chunks of the
given size.fileChannel
- The file channel.chunkSize
- the size of file chunks to read.offset
- The offset in the file to begin reading.length
- The number of bytes to read from the file.public static Flux<ByteBuffer> readFile(AsynchronousFileChannel fileChannel, long offset, long length)
Flux
from an AsynchronousFileChannel
which reads part of a file.fileChannel
- The file channel.offset
- The offset in the file to begin reading.length
- The number of bytes to read from the file.public static Flux<ByteBuffer> readFile(AsynchronousFileChannel fileChannel)
Flux
from an AsynchronousFileChannel
which reads the entire file.fileChannel
- The file channel.Copyright © 2021 Microsoft Corporation. All rights reserved.