Package com.azure.core.util.io
Class IOUtils
java.lang.Object
com.azure.core.util.io.IOUtils
Utilities related to IO operations that involve channels, streams, byte transfers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic AsynchronousByteChannel
toAsynchronousByteChannel
(AsynchronousFileChannel fileChannel, long position) AdaptsAsynchronousFileChannel
toAsynchronousByteChannel
.static void
transfer
(ReadableByteChannel source, WritableByteChannel destination) Transfers bytes fromReadableByteChannel
toWritableByteChannel
.transferAsync
(ReadableByteChannel source, AsynchronousByteChannel destination) Transfers bytes fromReadableByteChannel
toAsynchronousByteChannel
.transferStreamResponseToAsynchronousByteChannel
(AsynchronousByteChannel targetChannel, StreamResponse sourceResponse, BiFunction<Throwable, Long, Mono<StreamResponse>> onErrorResume, ProgressReporter progressReporter, int maxRetries) Transfers theStreamResponse
content toAsynchronousByteChannel
.
-
Method Details
-
toAsynchronousByteChannel
public static AsynchronousByteChannel toAsynchronousByteChannel(AsynchronousFileChannel fileChannel, long position) AdaptsAsynchronousFileChannel
toAsynchronousByteChannel
.- Parameters:
fileChannel
- TheAsynchronousFileChannel
.position
- The position in the file to begin writing or reading thecontent
.- Returns:
- A
AsynchronousByteChannel
that delegates tofileChannel
. - Throws:
NullPointerException
- WhenfileChannel
is null.IllegalArgumentException
- Whenposition
is negative.
-
transfer
public static void transfer(ReadableByteChannel source, WritableByteChannel destination) throws IOException Transfers bytes fromReadableByteChannel
toWritableByteChannel
.- Parameters:
source
- A sourceReadableByteChannel
.destination
- A destinationWritableByteChannel
.- Throws:
IOException
- When I/O operation fails.NullPointerException
- Whensource
is null.NullPointerException
- Whendestination
is null.
-
transferAsync
public static Mono<Void> transferAsync(ReadableByteChannel source, AsynchronousByteChannel destination) Transfers bytes fromReadableByteChannel
toAsynchronousByteChannel
.- Parameters:
source
- A sourceReadableByteChannel
.destination
- A destinationAsynchronousByteChannel
.- Returns:
- A
Mono
that completes when transfer is finished. - Throws:
NullPointerException
- Whensource
is null.NullPointerException
- Whendestination
is null.
-
transferStreamResponseToAsynchronousByteChannel
public static Mono<Void> transferStreamResponseToAsynchronousByteChannel(AsynchronousByteChannel targetChannel, StreamResponse sourceResponse, BiFunction<Throwable, Long, Mono<StreamResponse>> onErrorResume, ProgressReporter progressReporter, int maxRetries) Transfers theStreamResponse
content toAsynchronousByteChannel
. Resumes the transfer in case of errors.- Parameters:
targetChannel
- The destinationAsynchronousByteChannel
.sourceResponse
- The initialStreamResponse
.onErrorResume
- ABiFunction
ofThrowable
andLong
which is used to resume downloading when an error occurs. The function accepts aThrowable
and offset at the destination from beginning of writing at which the error occurred.progressReporter
- TheProgressReporter
.maxRetries
- The maximum number of times a download can be resumed when an error occurs.- Returns:
- A
Mono
which completion indicates successful transfer.
-