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.transferAsync(ReadableByteChannel source, AsynchronousByteChannel destination) 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- Whensourceis null.NullPointerException- Whendestinationis 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- Whensourceis null.NullPointerException- Whendestinationis 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.
-