public final class IoUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
canOpenReadOnly(String path)
Do not use.
|
static void |
close(FileDescriptor fd)
Calls close(2) on 'fd'.
|
static void |
closeQuietly(AutoCloseable closeable)
Closes 'closeable', ignoring any checked exceptions.
|
static void |
closeQuietly(FileDescriptor fd)
Closes 'fd', ignoring any exceptions.
|
static void |
closeQuietly(Socket socket)
Closes 'socket', ignoring any exceptions.
|
static File |
createTemporaryDirectory(String prefix)
Creates a unique new temporary directory under "java.io.tmpdir".
|
static void |
deleteContents(File dir)
Deprecated.
Use
createTemporaryDirectory(java.lang.String) instead. |
static byte[] |
readFileAsByteArray(String absolutePath)
Returns the contents of 'path' as a byte array.
|
static String |
readFileAsString(String absolutePath)
Returns the contents of 'path' as a string.
|
static void |
setBlocking(FileDescriptor fd,
boolean blocking)
Sets 'fd' to be blocking or non-blocking, according to the state of 'blocking'.
|
static void |
throwInterruptedIoException() |
public static void close(FileDescriptor fd) throws IOException
IOExceptionpublic static void closeQuietly(AutoCloseable closeable)
public static void closeQuietly(FileDescriptor fd)
public static void closeQuietly(Socket socket)
public static void setBlocking(FileDescriptor fd, boolean blocking) throws IOException
IOExceptionpublic static byte[] readFileAsByteArray(String absolutePath) throws IOException
IOExceptionpublic static String readFileAsString(String absolutePath) throws IOException
IOExceptionpublic static void deleteContents(File dir) throws IOException
createTemporaryDirectory(java.lang.String) instead.IOExceptionpublic static File createTemporaryDirectory(String prefix)
public static boolean canOpenReadOnly(String path)
path can be opened read-only. Similar to File.exists, but doesn't
require read permission on the parent, so it'll work in more cases, and allow you to
remove read permission from more directories. Everyone else should just open(2) and then
use the fd, but the loadLibrary API is broken by its need to ask ClassLoaders where to
find a .so rather than just calling dlopen(3).public static void throwInterruptedIoException()
throws InterruptedIOException
InterruptedIOException