public final class IOTools extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
IOSTATUS_INTERRUPTED |
| Modifier and Type | Method and Description |
|---|---|
static long |
addressFor(ByteBuffer byteBuffer) |
static void |
clean(ByteBuffer bb) |
static void |
createDirectories(Path dir) |
static Path |
createTempDirectory(String s) |
static File |
createTempFile(String s) |
static boolean |
deleteDirWithFiles(@NotNull File dir) |
static boolean |
deleteDirWithFiles(@NotNull File dir,
int maxDepth) |
static boolean |
deleteDirWithFiles(String... dirs) |
static boolean |
deleteDirWithFiles(@NotNull String dir,
int maxDepth) |
static void |
deleteDirWithFilesOrThrow(File... dirs)
Canonical usage is to call this *before* your test so you fail fast if you can't delete
|
static void |
deleteDirWithFilesOrThrow(String... dirs) |
static void |
deleteDirWithFilesOrWait(long timeoutMs,
@NotNull File dir)
Ensures that directory is absent or deleted, awaits for given timeout if necessary.
|
static boolean |
isDirectBuffer(ByteBuffer byteBuffer) |
static int |
normaliseIOStatus(int n) |
static InputStream |
open(URL url)
Creates and returns a new InputStream from the provided
url. |
static byte[] |
readAsBytes(InputStream is) |
static byte[] |
readFile(Class<?> clazz,
@NotNull String name)
This method first looks for the file in the classpath.
|
static boolean |
shallowDeleteDirWithFiles(@NotNull File dir) |
static boolean |
shallowDeleteDirWithFiles(@NotNull String directory) |
static @NotNull String |
tempName(@NotNull String filename) |
static void |
unmonitor(Object t) |
static @NotNull URL |
urlFor(Class<?> clazz,
String name) |
static @NotNull URL |
urlFor(ClassLoader classLoader,
String name) |
static void |
writeFile(@NotNull String filename,
@NotNull byte[] bytes) |
public static final int IOSTATUS_INTERRUPTED
public static boolean shallowDeleteDirWithFiles(@NotNull
@NotNull String directory)
throws IORuntimeException
IORuntimeExceptionpublic static boolean shallowDeleteDirWithFiles(@NotNull
@NotNull File dir)
throws IORuntimeException
IORuntimeExceptionpublic static boolean deleteDirWithFiles(@NotNull
String... dirs)
throws IORuntimeException
IORuntimeExceptionpublic static boolean deleteDirWithFiles(@NotNull
@NotNull String dir,
int maxDepth)
throws IORuntimeException
IORuntimeExceptionpublic static boolean deleteDirWithFiles(@NotNull
@NotNull File dir)
throws IORuntimeException
IORuntimeExceptionpublic static boolean deleteDirWithFiles(@NotNull
@NotNull File dir,
int maxDepth)
throws IORuntimeException
IORuntimeExceptionpublic static void deleteDirWithFilesOrThrow(@NotNull
String... dirs)
throws IORuntimeException
IORuntimeExceptionpublic static void deleteDirWithFilesOrThrow(@NotNull
File... dirs)
throws IORuntimeException
dirs - dirsIORuntimeExceptionpublic static void deleteDirWithFilesOrWait(long timeoutMs,
@NotNull
@NotNull File dir)
timeoutMs - Time to ensure that the directory is absent.dir - Dir to delete.AssertionError - If timeout passed and the directory is still present.@NotNull public static @NotNull URL urlFor(Class<?> clazz, String name) throws FileNotFoundException
FileNotFoundException@NotNull public static @NotNull URL urlFor(ClassLoader classLoader, String name) throws FileNotFoundException
FileNotFoundExceptionpublic static InputStream open(URL url) throws IOException
url.
It is up to the caller to close the returned InputStream after being used.
url - to create an InputStream fromIOException - if the URL cannot be openedpublic static byte[] readFile(Class<?> clazz, @NotNull @NotNull String name) throws IOException
clazz - file to use to determine the class loader.name - Name of the fileIOException - FileNotFoundException thrown if file is not foundpublic static byte[] readAsBytes(InputStream is) throws IOException
IOExceptionpublic static void writeFile(@NotNull
@NotNull String filename,
@NotNull
@NotNull byte[] bytes)
throws IOException
IOExceptionpublic static void clean(ByteBuffer bb)
public static void createDirectories(Path dir) throws IOException
IOExceptionpublic static void unmonitor(Object t)
public static boolean isDirectBuffer(ByteBuffer byteBuffer)
public static long addressFor(ByteBuffer byteBuffer)
public static int normaliseIOStatus(int n)
Copyright © 2022. All rights reserved.