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 AsynchronousByteChanneltoAsynchronousByteChannel(AsynchronousFileChannel fileChannel, long position) AdaptsAsynchronousFileChanneltoAsynchronousByteChannel.static voidtransfer(ReadableByteChannel source, WritableByteChannel destination) Transfers bytes fromReadableByteChanneltoWritableByteChannel.static voidtransfer(ReadableByteChannel source, WritableByteChannel destination, Long estimatedSourceSize) Transfers bytes fromReadableByteChanneltoWritableByteChannel.transferAsync(ReadableByteChannel source, AsynchronousByteChannel destination) Transfers bytes fromReadableByteChanneltoAsynchronousByteChannel.transferAsync(ReadableByteChannel source, AsynchronousByteChannel destination, Long estimatedSourceSize) Transfers bytes fromReadableByteChanneltoAsynchronousByteChannel.transferStreamResponseToAsynchronousByteChannel(AsynchronousByteChannel targetChannel, StreamResponse sourceResponse, BiFunction<Throwable, Long, Mono<StreamResponse>> onErrorResume, ProgressReporter progressReporter, int maxRetries) Transfers theStreamResponsecontent toAsynchronousByteChannel.
-
Method Details
-
toAsynchronousByteChannel
public static AsynchronousByteChannel toAsynchronousByteChannel(AsynchronousFileChannel fileChannel, long position) AdaptsAsynchronousFileChanneltoAsynchronousByteChannel.- Parameters:
fileChannel- TheAsynchronousFileChannel.position- The position in the file to begin writing or reading thecontent.- Returns:
- A
AsynchronousByteChannelthat delegates tofileChannel. - Throws:
NullPointerException- WhenfileChannelis null.IllegalArgumentException- Whenpositionis negative.
-
transfer
public static void transfer(ReadableByteChannel source, WritableByteChannel destination) throws IOException Transfers bytes fromReadableByteChanneltoWritableByteChannel.- Parameters:
source- A sourceReadableByteChannel.destination- A destinationWritableByteChannel.- Throws:
IOException- When I/O operation fails.NullPointerException- Whensourceordestinationis null.
-
transfer
public static void transfer(ReadableByteChannel source, WritableByteChannel destination, Long estimatedSourceSize) throws IOException Transfers bytes fromReadableByteChanneltoWritableByteChannel.- Parameters:
source- A sourceReadableByteChannel.destination- A destinationWritableByteChannel.estimatedSourceSize- An estimated size of the source channel, may be null. Used to better determine the size of the buffer used to transfer data in an attempt to reduce read and write calls.- Throws:
IOException- When I/O operation fails.NullPointerException- Whensourceordestinationis null.
-
transferAsync
public static Mono<Void> transferAsync(ReadableByteChannel source, AsynchronousByteChannel destination) Transfers bytes fromReadableByteChanneltoAsynchronousByteChannel.- Parameters:
source- A sourceReadableByteChannel.destination- A destinationAsynchronousByteChannel.- Returns:
- A
Monothat completes when transfer is finished. - Throws:
NullPointerException- Whensourceordestinationis null.
-
transferAsync
public static Mono<Void> transferAsync(ReadableByteChannel source, AsynchronousByteChannel destination, Long estimatedSourceSize) Transfers bytes fromReadableByteChanneltoAsynchronousByteChannel.- Parameters:
source- A sourceReadableByteChannel.destination- A destinationAsynchronousByteChannel.estimatedSourceSize- An estimated size of the source channel, may be null. Used to better determine the size of the buffer used to transfer data in an attempt to reduce read and write calls.- Returns:
- A
Monothat completes when transfer is finished. - Throws:
NullPointerException- Whensourceordestinationis null.
-
transferStreamResponseToAsynchronousByteChannel
public static Mono<Void> transferStreamResponseToAsynchronousByteChannel(AsynchronousByteChannel targetChannel, StreamResponse sourceResponse, BiFunction<Throwable, Long, Mono<StreamResponse>> onErrorResume, ProgressReporter progressReporter, int maxRetries) Transfers theStreamResponsecontent toAsynchronousByteChannel. Resumes the transfer in case of errors.- Parameters:
targetChannel- The destinationAsynchronousByteChannel.sourceResponse- The initialStreamResponse.onErrorResume- ABiFunctionofThrowableandLongwhich is used to resume downloading when an error occurs. The function accepts aThrowableand 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
Monowhich completion indicates successful transfer.
-