public final class IOUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
IOUtil.RecursiveAsyncSupplierListener<T>
Recursive listener, forwarding error or cancel and calling onDone on error.
|
| Modifier and Type | Method and Description |
|---|---|
static IAsync<IOException> |
closeAsync(Closeable toClose)
Implement an asynchronous close using a task calling the synchronous close.
|
static AsyncSupplier<Long,IOException> |
copy(File src,
File dst,
byte priority,
long knownSize,
WorkProgress progress,
long work,
IAsync<?> startOn)
Copy a file.
|
static AsyncSupplier<Long,IOException> |
copy(IO.Readable input,
IO.Writable output,
long size,
boolean closeIOs,
WorkProgress progress,
long work)
Copy from a Readable to a Writable.
|
static <T extends IO.Writable.Seekable & IO.Readable.Seekable> |
copy(T io,
long src,
long dst,
long len)
Copy bytes inside a Seekable IO.
|
static <TResult,TError extends Exception> |
error(TError error,
AsyncSupplier<TResult,TError> result,
Consumer<Pair<TResult,TError>> ondone)
Shortcut to transfer an error to ondone if it is not null, and to the AsyncWork.
|
static <TResult,TError extends Exception> |
error(TError error,
Consumer<Pair<TResult,TError>> ondone)
Shortcut to transfer an error to ondone if it is not null, and create an AsyncWork with this error.
|
static <T> Consumer<IOException> |
errorConsumer(IAsync<IOException> async,
Consumer<Pair<T,IOException>> ondone)
Create a consumer that call forward the error to the given sync and call onDone.
|
static long |
getSizeSync(IO.Readable.Seekable io)
Get the size by seeking at the end if not an instanceof IO.KnownSize.
|
static IO |
getUnderlyingIO(IO io)
Get the underlying IO by going through the wrapped IO until the last one.
|
static TaskManager |
getUnderlyingTaskManager(IO io)
Get the underlying task manager by going through the wrapped IO.
|
static <T> void |
listenOnDone(AsyncSupplier<T,IOException> toListen,
AsyncSupplier<T,IOException> toUnblock,
Consumer<Pair<T,IOException>> ondone)
Listen to the given asynchronous operation, then unblock
toUnblock with its result/error/cancellation,
but calls ondone before if not null and the result is not cancelled. |
static <T,T2> void |
listenOnDone(AsyncSupplier<T,IOException> toListen,
Consumer<T> onReady,
IAsync<IOException> onErrorOrCancel,
Consumer<Pair<T2,IOException>> ondone)
Listen to
toListen, then calls onReady if it succeed. |
static <T,T2> void |
listenOnDone(AsyncSupplier<T,IOException> toListen,
Task<?,?> onReady,
IAsync<IOException> onErrorOrCancel,
Consumer<Pair<T2,IOException>> ondone)
Listen to
toListen, then launch onReady if it succeed. |
static <T> void |
listenOnDone(IAsync<IOException> toListen,
Runnable onReady,
IAsync<IOException> onErrorOrCancel,
Consumer<Pair<T,IOException>> ondone)
Listen to
toListen, then calls onReady if it succeed. |
static <TResult,TError extends Exception> |
notSuccess(IAsync<TError> sp,
AsyncSupplier<TResult,TError> result,
Consumer<Pair<TResult,TError>> ondone)
Shortcut to transfer error or cancellation.
|
static Task<Integer,IOException> |
readAsyncUsingSync(IO.Readable.Seekable io,
long pos,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Implement an asynchronous read using a task calling the synchronous one.
|
static Task<Integer,IOException> |
readAsyncUsingSync(IO.Readable io,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Implement an asynchronous read using a task calling the synchronous one.
|
static AsyncSupplier<byte[],IOException> |
readFully(File file,
byte priority)
Read the content of a file and return a byte array.
|
static void |
readFully(IO.Readable io,
AsyncSupplier<byte[],IOException> result)
Read fully into a byte[], and unblock the given result upon completion.
|
static int |
readFully(IO.Readable io,
ByteBuffer buffer)
Fill the remaining bytes of the given buffer.
|
static int |
readFully(IO.ReadableByteStream io,
byte[] buffer)
Fill the given buffer.
|
static int |
readFully(IO.ReadableByteStream io,
byte[] buffer,
int off,
int len)
Read the given number of bytes.
|
static AsyncSupplier<UnprotectedStringBuffer,IOException> |
readFullyAsString(IO.Readable io,
Charset charset,
byte priority)
Read all bytes from the given Readable and convert it as a String using the given charset encoding.
|
static String |
readFullyAsStringSync(File file,
Charset charset)
Read all bytes from the given file and convert it as a String using the given charset encoding.
|
static String |
readFullyAsStringSync(InputStream input,
Charset charset)
Read all bytes from the given InputStream and convert it as a String using the given charset encoding.
|
static void |
readFullyAsStringSync(InputStream input,
Charset charset,
StringBuilder s)
Read all bytes from the given Readable and append them to the given StringBuilder using the given charset encoding.
|
static String |
readFullyAsStringSync(IO.Readable io,
Charset charset)
Read all bytes from the given Readable and convert it as a String using the given charset encoding.
|
static void |
readFullyAsStringSync(IO.Readable io,
Charset charset,
StringBuilder s)
Read all bytes from the given Readable and append them to the given StringBuilder using the given charset encoding.
|
static AsyncSupplier<Integer,IOException> |
readFullyAsync(IO.Readable.Seekable io,
long pos,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Fill the remaining bytes of the given buffer.
|
static AsyncSupplier<Integer,IOException> |
readFullyAsync(IO.Readable io,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Fill the remaining bytes of the given buffer asynchronously.
|
static AsyncSupplier<Integer,IOException> |
readFullyAsync(IO.Readable io,
ByteBuffer buffer,
int done,
Consumer<Pair<Integer,IOException>> ondone)
Fill the remaining bytes of the given buffer asynchronously.
|
static AsyncSupplier<ByteBuffersIO,IOException> |
readFullyAsync(IO.Readable io,
int bufferSize)
Read the content of IO.Readable in memory and put it into a ByteBuffersIO.
|
static Task<Integer,IOException> |
readFullyAsyncUsingSync(IO.Readable.Seekable io,
long pos,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Implement an asynchronous read using a task calling the synchronous one.
|
static Task<Integer,IOException> |
readFullyAsyncUsingSync(IO.Readable io,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Implement an asynchronous read using a task calling the synchronous one.
|
static void |
readFullyKnownSize(IO.Readable io,
int size,
AsyncSupplier<byte[],IOException> result)
Read fully into a byte[], and unblock the given result upon completion.
|
static <T extends IO.Readable & IO.KnownSize> |
readFullyKnownSize(T io,
AsyncSupplier<byte[],IOException> result)
Read fully into a byte[], and unblock the given result upon completion.
|
static int |
readFullySync(IO.Readable.Seekable io,
long pos,
ByteBuffer buffer)
Fill the remaining bytes of the given buffer.
|
static int |
readFullySyncUsingAsync(IO.Readable.Seekable io,
long pos,
ByteBuffer buffer)
Implement a synchronous read using an asynchronous one and blocking until it finishes.
|
static int |
readFullySyncUsingAsync(IO.Readable io,
ByteBuffer buffer)
Implement a synchronous read using an asynchronous one and blocking until it finishes.
|
static int |
readSyncUsingAsync(IO.Readable.Seekable io,
long pos,
ByteBuffer buffer)
Implement a synchronous read using an asynchronous one and blocking until it finishes.
|
static int |
readSyncUsingAsync(IO.Readable io,
ByteBuffer buffer)
Implement a synchronous read using an asynchronous one and blocking until it finishes.
|
static Task<Long,IOException> |
seekAsyncUsingSync(IO.Seekable io,
IO.Seekable.SeekType type,
long move,
Consumer<Pair<Long,IOException>> ondone)
Implement an asynchronous seek using a task calling a synchronous one.
|
static long |
seekSyncUsingAsync(IO.Seekable io,
IO.Seekable.SeekType type,
long move)
Implement a synchronous sync by calling an asynchronous one and blocking until the result is available.
|
static Task<Void,IOException> |
setSizeAsyncUsingSync(IO.Resizable io,
long newSize,
byte priority)
Implement an asynchronous setSize using a task calling a synchronous one.
|
static AsyncSupplier<Long,IOException> |
skipAsyncByReading(IO.Readable io,
long n,
Consumer<Pair<Long,IOException>> ondone)
Implement an asynchronous skip using readAsync.
|
static AsyncSupplier<Long,IOException> |
skipAsyncUsingSync(IO.Readable io,
long n,
Consumer<Pair<Long,IOException>> ondone)
Implement an asynchronous skip using a task calling a synchronous skip.
|
static long |
skipSyncByReading(IO.Readable io,
long n)
Implement a synchronous skip using a synchronous read.
|
static long |
skipSyncUsingAsync(IO.Readable io,
long n)
Implement a synchronous skip using an asynchronous one and blocking until it finishes.
|
static <TResult,TError extends Exception> |
success(TResult res,
AsyncSupplier<TResult,TError> result,
Consumer<Pair<TResult,TError>> ondone)
Shortcut to transfer a result to ondone if it is not null, and to the AsyncWork.
|
static <TResult,TError extends Exception> |
success(TResult result,
Consumer<Pair<TResult,TError>> ondone)
Shortcut to transfer a result to ondone if it is not null, and create an AsyncWork with this result.
|
static AsyncSupplier<File,IOException> |
toTempFile(byte[] bytes)
Create a temporary file with the given content.
|
static AsyncSupplier<File,IOException> |
toTempFile(IO.Readable io)
Write the given Readable to a temporary file, and return the temporary file.
|
static Task<Integer,IOException> |
writeAsyncUsingSync(IO.Writable.Seekable io,
long pos,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Implement an asynchronous write using a task calling a synchronous write.
|
static Task<Integer,IOException> |
writeAsyncUsingSync(IO.Writable io,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Implement an asynchronous write using a task calling a synchronous write.
|
static int |
writeSyncUsingAsync(IO.Writable.Seekable io,
long pos,
ByteBuffer buffer)
Implement a synchronous write using an asynchronous one and blocking until it finishes.
|
static int |
writeSyncUsingAsync(IO.Writable io,
ByteBuffer buffer)
Implement a synchronous write using an asynchronous one and blocking until it finishes.
|
public static int readFully(IO.Readable io, ByteBuffer buffer) throws IOException
io - the readable to read frombuffer - the buffer to fillIOException - in case of error reading bytespublic static int readFully(IO.ReadableByteStream io, byte[] buffer) throws IOException
io - the readable to read frombuffer - the buffer to fillIOException - in case of error reading bytespublic static int readFully(IO.ReadableByteStream io, byte[] buffer, int off, int len) throws IOException
io - the readable to read frombuffer - the buffer to filloff - the offset of the buffer from which to filllen - the number of bytes to readIOException - in case of error reading bytespublic static void readFully(IO.Readable io, AsyncSupplier<byte[],IOException> result)
public static <T extends IO.Readable & IO.KnownSize> void readFullyKnownSize(T io, AsyncSupplier<byte[],IOException> result)
public static void readFullyKnownSize(IO.Readable io, int size, AsyncSupplier<byte[],IOException> result)
public static int readFullySync(IO.Readable.Seekable io, long pos, ByteBuffer buffer) throws IOException
io - the readable to read frompos - the position in the io to start frombuffer - the buffer to fillIOException - in case of error reading bytespublic static AsyncSupplier<Integer,IOException> readFullyAsync(IO.Readable io, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
io - the readable to read frombuffer - the buffer to fillondone - a listener to call before to return the resultpublic static AsyncSupplier<Integer,IOException> readFullyAsync(IO.Readable io, ByteBuffer buffer, int done, Consumer<Pair<Integer,IOException>> ondone)
io - the readable to read frombuffer - the buffer to filldone - number of bytes already read (will be added to the returned number of bytes read)ondone - a listener to call before to return the resultpublic static AsyncSupplier<Integer,IOException> readFullyAsync(IO.Readable.Seekable io, long pos, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
io - the readable to read frompos - the position in the io to start frombuffer - the buffer to fillondone - a listener to call before to return the resultpublic static AsyncSupplier<ByteBuffersIO,IOException> readFullyAsync(IO.Readable io, int bufferSize)
public static Task<Integer,IOException> readAsyncUsingSync(IO.Readable io, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
io - the readable to read frombuffer - the buffer to fillondone - a listener to call before to return the resultpublic static Task<Integer,IOException> readAsyncUsingSync(IO.Readable.Seekable io, long pos, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
io - the readable to read frompos - the position in the io to start frombuffer - the buffer to fillondone - a listener to call before to return the resultpublic static Task<Integer,IOException> readFullyAsyncUsingSync(IO.Readable io, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
io - the readable to read frombuffer - the buffer to fillondone - a listener to call before to return the resultpublic static Task<Integer,IOException> readFullyAsyncUsingSync(IO.Readable.Seekable io, long pos, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
io - the readable to read frompos - the position in the io to start frombuffer - the buffer to fillondone - a listener to call before to return the resultpublic static long skipSyncByReading(IO.Readable io, long n) throws IOException
IOExceptionpublic static AsyncSupplier<Long,IOException> skipAsyncUsingSync(IO.Readable io, long n, Consumer<Pair<Long,IOException>> ondone)
public static AsyncSupplier<Long,IOException> skipAsyncByReading(IO.Readable io, long n, Consumer<Pair<Long,IOException>> ondone)
public static AsyncSupplier<File,IOException> toTempFile(IO.Readable io)
public static AsyncSupplier<File,IOException> toTempFile(byte[] bytes)
public static int readSyncUsingAsync(IO.Readable io, ByteBuffer buffer) throws IOException
IOExceptionpublic static int readSyncUsingAsync(IO.Readable.Seekable io, long pos, ByteBuffer buffer) throws IOException
IOExceptionpublic static int readFullySyncUsingAsync(IO.Readable io, ByteBuffer buffer) throws IOException
IOExceptionpublic static int readFullySyncUsingAsync(IO.Readable.Seekable io, long pos, ByteBuffer buffer) throws IOException
IOExceptionpublic static long skipSyncUsingAsync(IO.Readable io, long n) throws IOException
IOExceptionpublic static int writeSyncUsingAsync(IO.Writable io, ByteBuffer buffer) throws IOException
IOExceptionpublic static int writeSyncUsingAsync(IO.Writable.Seekable io, long pos, ByteBuffer buffer) throws IOException
IOExceptionpublic static Task<Integer,IOException> writeAsyncUsingSync(IO.Writable io, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
public static Task<Integer,IOException> writeAsyncUsingSync(IO.Writable.Seekable io, long pos, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
public static AsyncSupplier<UnprotectedStringBuffer,IOException> readFullyAsString(IO.Readable io, Charset charset, byte priority)
public static void readFullyAsStringSync(IO.Readable io, Charset charset, StringBuilder s) throws IOException
IOExceptionpublic static void readFullyAsStringSync(InputStream input, Charset charset, StringBuilder s) throws IOException
IOExceptionpublic static String readFullyAsStringSync(IO.Readable io, Charset charset) throws IOException
IOExceptionpublic static String readFullyAsStringSync(File file, Charset charset) throws IOException
IOExceptionpublic static String readFullyAsStringSync(InputStream input, Charset charset) throws IOException
IOExceptionpublic static Task<Long,IOException> seekAsyncUsingSync(IO.Seekable io, IO.Seekable.SeekType type, long move, Consumer<Pair<Long,IOException>> ondone)
public static long seekSyncUsingAsync(IO.Seekable io, IO.Seekable.SeekType type, long move) throws IOException
IOExceptionpublic static Task<Void,IOException> setSizeAsyncUsingSync(IO.Resizable io, long newSize, byte priority)
public static AsyncSupplier<Long,IOException> copy(IO.Readable input, IO.Writable output, long size, boolean closeIOs, WorkProgress progress, long work)
input - input to read fromoutput - output to write tosize - number of bytes to copy, or -1 if it is not knowncloseIOs - if true both IOs will be closed at the end of the copyprogress - progresswork - amount of work in the progresspublic static <T extends IO.Writable.Seekable & IO.Readable.Seekable> Async<IOException> copy(T io, long src, long dst, long len)
io - the IOsrc - source positiondst - target positionlen - number of bytes to copypublic static AsyncSupplier<Long,IOException> copy(File src, File dst, byte priority, long knownSize, WorkProgress progress, long work, IAsync<?> startOn)
public static IAsync<IOException> closeAsync(Closeable toClose)
public static AsyncSupplier<byte[],IOException> readFully(File file, byte priority)
public static TaskManager getUnderlyingTaskManager(IO io)
public static IO getUnderlyingIO(IO io)
public static <T> void listenOnDone(AsyncSupplier<T,IOException> toListen, AsyncSupplier<T,IOException> toUnblock, Consumer<Pair<T,IOException>> ondone)
toUnblock with its result/error/cancellation,
but calls ondone before if not null and the result is not cancelled.public static <T,T2> void listenOnDone(AsyncSupplier<T,IOException> toListen, Consumer<T> onReady, IAsync<IOException> onErrorOrCancel, Consumer<Pair<T2,IOException>> ondone)
toListen, then calls onReady if it succeed.
In case of error or cancellation, the error or cancellation event is given to onErrorOrCancel.
If ondone is not null, it is called before onReady and onErrorOrCancel.public static <T,T2> void listenOnDone(AsyncSupplier<T,IOException> toListen, Task<?,?> onReady, IAsync<IOException> onErrorOrCancel, Consumer<Pair<T2,IOException>> ondone)
toListen, then launch onReady if it succeed.
In case of error or cancellation, the error or cancellation event is given to onErrorOrCancel.
If ondone is not null, it is called before onReady and onErrorOrCancel.public static <T> void listenOnDone(IAsync<IOException> toListen, Runnable onReady, IAsync<IOException> onErrorOrCancel, Consumer<Pair<T,IOException>> ondone)
toListen, then calls onReady if it succeed.
In case of error or cancellation, the error or cancellation event is given to onErrorOrCancel.
If ondone is not null, it is called before onReady and onErrorOrCancel.public static <T> Consumer<IOException> errorConsumer(IAsync<IOException> async, Consumer<Pair<T,IOException>> ondone)
public static <TResult,TError extends Exception> void error(TError error, AsyncSupplier<TResult,TError> result, Consumer<Pair<TResult,TError>> ondone)
public static <TResult,TError extends Exception> AsyncSupplier<TResult,TError> error(TError error, Consumer<Pair<TResult,TError>> ondone)
public static <TResult,TError extends Exception> void success(TResult res, AsyncSupplier<TResult,TError> result, Consumer<Pair<TResult,TError>> ondone)
public static <TResult,TError extends Exception> AsyncSupplier<TResult,TError> success(TResult result, Consumer<Pair<TResult,TError>> ondone)
public static <TResult,TError extends Exception> void notSuccess(IAsync<TError> sp, AsyncSupplier<TResult,TError> result, Consumer<Pair<TResult,TError>> ondone)
public static long getSizeSync(IO.Readable.Seekable io) throws IOException
IOExceptionCopyright © 2019. All rights reserved.