public interface IOUtils
| 限定符和类型 | 方法和说明 |
|---|---|
static IOException |
asIOException(Throwable t) |
static <T> T |
bytes2Object(byte[] bytes,
Class<T> clazz) |
static void |
cleanup(org.slf4j.Logger log,
Closeable... closeables)
Close the Closeable objects and ignore any
Throwable or
null pointers. |
static <T> T |
getFromFuture(CompletableFuture<T> future,
Supplier<Object> name) |
static <T> T |
getFromFuture(CompletableFuture<T> future,
Supplier<Object> name,
TimeDuration timeout) |
static byte[] |
object2Bytes(Object obj)
Serialize the given object to a byte array using
ObjectOutputStream.writeObject(Object). |
static long |
preallocate(FileChannel fc,
long size,
ByteBuffer fill) |
static void |
readFully(InputStream in,
byte[] buf,
int off,
int len)
Reads len bytes in a loop.
|
static void |
readFully(InputStream in,
int buffSize) |
static <T> T |
readObject(InputStream in,
Class<T> clazz)
Read an object from the given input stream.
|
static boolean |
shouldReconnect(Throwable e) |
static void |
skipFully(InputStream in,
long len)
Similar to readFully().
|
static InterruptedIOException |
toInterruptedIOException(String message,
InterruptedException e) |
static IOException |
toIOException(ExecutionException e) |
static void |
writeFully(FileChannel fc,
ByteBuffer buf,
long offset)
Write a ByteBuffer to a FileChannel at a given offset,
handling short writes.
|
static InterruptedIOException toInterruptedIOException(String message, InterruptedException e)
static IOException asIOException(Throwable t)
static IOException toIOException(ExecutionException e)
static <T> T getFromFuture(CompletableFuture<T> future, Supplier<Object> name) throws IOException
IOExceptionstatic <T> T getFromFuture(CompletableFuture<T> future, Supplier<Object> name, TimeDuration timeout) throws IOException
IOExceptionstatic boolean shouldReconnect(Throwable e)
static void readFully(InputStream in, int buffSize) throws IOException
IOExceptionstatic void readFully(InputStream in, byte[] buf, int off, int len) throws IOException
in - InputStream to read frombuf - The buffer to filloff - offset from the bufferlen - the length of bytes to readIOException - if it could not read requested number of bytes
for any reason (including EOF)static void writeFully(FileChannel fc, ByteBuffer buf, long offset) throws IOException
fc - The FileChannel to write tobuf - The input bufferoffset - The offset in the file to start writing atIOException - On I/O errorstatic long preallocate(FileChannel fc, long size, ByteBuffer fill) throws IOException
IOExceptionstatic void skipFully(InputStream in, long len) throws IOException
in - The InputStream to skip bytes fromlen - number of bytes to skip.IOException - if it could not skip requested number of bytes
for any reason (including EOF)static void cleanup(org.slf4j.Logger log,
Closeable... closeables)
Throwable or
null pointers. Must only be used for cleanup in exception handlers.log - the log to record problems to at debug level. Can be null.closeables - the objects to closestatic byte[] object2Bytes(Object obj)
ObjectOutputStream.writeObject(Object).static <T> T bytes2Object(byte[] bytes,
Class<T> clazz)
static <T> T readObject(InputStream in, Class<T> clazz)
T - The class type.in - input stream to read from.clazz - the class of the object.Copyright © 2017–2023 The Apache Software Foundation. All rights reserved.