public final class IOUtils extends Object
Modifier and Type | Method and Description |
---|---|
static int |
chooseFreePort()
Binds to a free ephemeral port, and then releases it.
|
static void |
closeQuietly(Closeable closeable)
Closes a
Closeable and logs the exception, if any. |
static void |
deleteRecursively(Path rootDir)
Deletes the given path, and if it is a directory, all files and subdirectories within it.
|
static List<Path> |
listFiles(Path dir,
String glob) |
public static void deleteRecursively(Path rootDir) throws IOException
rootDir
- directory to deleteIOException
- if any error occurs while deleting files or directoriespublic static List<Path> listFiles(Path dir, String glob) throws IOException
dir
- directory to listglob
- glob pattern for files that should be returned, which can span subdirectories
as in patterns like * /*
Path
s, including both files and directories, matching the glob pattern.
No path containing an element whose name starts with "." is returned.
Returned paths are also ordered lexicographically.IOException
- if an error occurs while accessing the file systempublic static void closeQuietly(Closeable closeable)
Closeable
and logs the exception, if any. This is only suitable for closing
objects where a failure to close does not impact correctness -- for example, an input stream
that is already fully read, but not an output stream which may fail when flushing final
output.closeable
- thing to closepublic static int chooseFreePort() throws IOException
IOException
- if an error occurs while binding to a portCopyright © 2014–2018. All rights reserved.