public class IOUtil extends Object
| Constructor and Description |
|---|
IOUtil() |
| Modifier and Type | Method and Description |
|---|---|
static ISynchronizationPoint<IOException> |
closeAsync(Closeable toClose)
Implement an asynchronous close using a task calling the synchronous close.
|
static AsyncWork<Long,IOException> |
copy(File src,
File dst,
byte priority,
long knownSize,
WorkProgress progress,
long work,
ISynchronizationPoint<?> startOn)
Copy a file.
|
static AsyncWork<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 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(AsyncWork<T,IOException> toListen,
AsyncWork<T,IOException> toUnblock,
RunnableWithParameter<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(AsyncWork<T,IOException> toListen,
Listener<T> onReady,
ISynchronizationPoint<IOException> onErrorOrCancel,
RunnableWithParameter<Pair<T2,IOException>> ondone)
Listen to
toListen, then calls onReady if it succeed. |
static Task<Integer,IOException> |
readAsyncUsingSync(IO.Readable.Seekable io,
long pos,
ByteBuffer buffer,
RunnableWithParameter<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,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
Implement an asynchronous read using a task calling the synchronous one.
|
static AsyncWork<byte[],IOException> |
readFully(File file,
byte priority)
Read the content of a file and return a byte array.
|
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 Task<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 AsyncWork<Integer,IOException> |
readFullyAsync(IO.Readable.Seekable io,
long pos,
ByteBuffer buffer,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
Fill the remaining bytes of the given buffer.
|
static AsyncWork<Integer,IOException> |
readFullyAsync(IO.Readable io,
ByteBuffer buffer,
int done,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
Fill the remaining bytes of the given buffer asynchronously.
|
static AsyncWork<Integer,IOException> |
readFullyAsync(IO.Readable io,
ByteBuffer buffer,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
Fill the remaining bytes of the given buffer asynchronously.
|
static Task<Integer,IOException> |
readFullyAsyncUsingSync(IO.Readable.Seekable io,
long pos,
ByteBuffer buffer,
RunnableWithParameter<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,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
Implement an asynchronous read using a task calling the synchronous one.
|
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.Readable.Seekable io,
IO.Seekable.SeekType type,
long move,
RunnableWithParameter<Pair<Long,IOException>> ondone)
Implement an asynchronous seek using a task calling a synchronous one.
|
static long |
seekSyncUsingAsync(IO.Readable.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 AsyncWork<Long,IOException> |
skipAsyncByReading(IO.Readable io,
long n,
RunnableWithParameter<Pair<Long,IOException>> ondone)
Implement an asynchronous skip using readAsync.
|
static AsyncWork<Long,IOException> |
skipAsyncUsingSync(IO.Readable io,
long n,
RunnableWithParameter<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 File |
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,
RunnableWithParameter<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,
RunnableWithParameter<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 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 AsyncWork<Integer,IOException> readFullyAsync(IO.Readable io, ByteBuffer buffer, RunnableWithParameter<Pair<Integer,IOException>> ondone)
io - the readable to read frombuffer - the buffer to fillondone - a listener to call before to return the resultpublic static AsyncWork<Integer,IOException> readFullyAsync(IO.Readable io, ByteBuffer buffer, int done, RunnableWithParameter<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 AsyncWork<Integer,IOException> readFullyAsync(IO.Readable.Seekable io, long pos, ByteBuffer buffer, RunnableWithParameter<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> readAsyncUsingSync(IO.Readable io, ByteBuffer buffer, RunnableWithParameter<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, RunnableWithParameter<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, RunnableWithParameter<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, RunnableWithParameter<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 AsyncWork<Long,IOException> skipAsyncUsingSync(IO.Readable io, long n, RunnableWithParameter<Pair<Long,IOException>> ondone)
public static AsyncWork<Long,IOException> skipAsyncByReading(IO.Readable io, long n, RunnableWithParameter<Pair<Long,IOException>> ondone)
public static File toTempFile(IO.Readable io) throws IOException
IOExceptionpublic 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, RunnableWithParameter<Pair<Integer,IOException>> ondone)
public static Task<Integer,IOException> writeAsyncUsingSync(IO.Writable.Seekable io, long pos, ByteBuffer buffer, RunnableWithParameter<Pair<Integer,IOException>> ondone)
public static Task<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.Readable.Seekable io, IO.Seekable.SeekType type, long move, RunnableWithParameter<Pair<Long,IOException>> ondone)
public static long seekSyncUsingAsync(IO.Readable.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 AsyncWork<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> SynchronizationPoint<IOException> copy(T io, long src, long dst, long len)
io - the IOsrc - source positiondst - target positionlen - number of bytes to copypublic static AsyncWork<Long,IOException> copy(File src, File dst, byte priority, long knownSize, WorkProgress progress, long work, ISynchronizationPoint<?> startOn)
public static ISynchronizationPoint<IOException> closeAsync(Closeable toClose)
public static AsyncWork<byte[],IOException> readFully(File file, byte priority)
public static TaskManager getUnderlyingTaskManager(IO io)
public static IO getUnderlyingIO(IO io)
public static <T> void listenOnDone(AsyncWork<T,IOException> toListen, AsyncWork<T,IOException> toUnblock, RunnableWithParameter<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(AsyncWork<T,IOException> toListen, Listener<T> onReady, ISynchronizationPoint<IOException> onErrorOrCancel, RunnableWithParameter<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.Copyright © 2017. All rights reserved.