public final class PathUtils
extends java.lang.Object
propagate(IOException, Path, boolean)
et al globally.Modifier and Type | Class and Description |
---|---|
static interface |
PathUtils.IOConsumer |
static interface |
PathUtils.IOToLongFunction<V> |
Modifier and Type | Method and Description |
---|---|
static void |
clearOnExitThreads() |
static boolean |
createDirectoriesIfNotExists(java.nio.file.Path path) |
static boolean |
createDirectoryIfNotExists(java.nio.file.Path path) |
static boolean |
createFileIfNotExists(java.nio.file.Path path) |
static void |
delete(java.nio.file.Path file) |
static void |
delete(java.nio.file.Path file,
com.google.common.util.concurrent.RateLimiter rateLimiter) |
static java.lang.Throwable |
delete(java.nio.file.Path file,
java.lang.Throwable accumulate) |
static java.lang.Throwable |
delete(java.nio.file.Path file,
java.lang.Throwable accumulate,
com.google.common.util.concurrent.RateLimiter rateLimiter) |
static void |
deleteIfExists(java.nio.file.Path file) |
static void |
deleteOnExit(java.nio.file.Path file)
Schedules deletion of the file only on JVM shutdown.
|
static void |
deleteRecursive(java.nio.file.Path path)
Deletes all files and subdirectories under "path".
|
static void |
deleteRecursive(java.nio.file.Path path,
com.google.common.util.concurrent.RateLimiter rateLimiter)
Deletes all files and subdirectories under "path".
|
static void |
deleteRecursiveOnExit(java.nio.file.Path dir)
Schedules deletion of all file and subdirectories under "dir" on JVM shutdown.
|
static boolean |
exists(java.nio.file.Path path) |
static java.lang.String |
filename(java.nio.file.Path path) |
static java.nio.file.Path |
findExistingAncestor(java.nio.file.Path file) |
static void |
forEach(java.nio.file.Path path,
java.util.function.Consumer<java.nio.file.Path> forEach) |
static void |
forEachRecursive(java.nio.file.Path path,
java.util.function.Consumer<java.nio.file.Path> forEach) |
static boolean |
isContained(java.nio.file.Path folder,
java.nio.file.Path file)
Return true if file's canonical path is contained in folder's canonical path.
|
static boolean |
isDirectory(java.nio.file.Path path) |
static boolean |
isFile(java.nio.file.Path path) |
static <T> T[] |
list(java.nio.file.Path path,
java.util.function.Function<java.util.stream.Stream<java.nio.file.Path>,java.util.stream.Stream<T>> transform,
java.util.function.IntFunction<T[]> arrayFactory) |
static java.nio.channels.FileChannel |
newReadChannel(java.nio.file.Path path) |
static java.nio.channels.FileChannel |
newReadWriteChannel(java.nio.file.Path path) |
static java.nio.channels.FileChannel |
newWriteAppendChannel(java.nio.file.Path path) |
static java.nio.channels.FileChannel |
newWriteOverwriteChannel(java.nio.file.Path path) |
static <E extends java.io.IOException> |
propagate(E ioe,
java.nio.file.Path path,
boolean write)
propagate an IOException either as itself or an FSWriteError or FSReadError
|
static java.lang.RuntimeException |
propagateUnchecked(java.io.IOException ioe,
java.nio.file.Path path,
boolean write)
propagate an IOException as an FSWriteError, FSReadError or UncheckedIOException
|
static java.lang.RuntimeException |
propagateUnchecked(java.lang.String message,
java.io.IOException ioe,
java.nio.file.Path path,
boolean write)
propagate an IOException as an FSWriteError, FSReadError or UncheckedIOException
|
static java.nio.file.NoSuchFileException |
propagateUncheckedOrNoSuchFileException(java.io.IOException ioe,
java.nio.file.Path path,
boolean write)
propagate an IOException as an FSWriteError, FSReadError or UncheckedIOException - except for NoSuchFileException
|
static void |
rename(java.nio.file.Path from,
java.nio.file.Path to) |
static void |
runOnExitThreadsAndClear() |
static void |
setDeletionListener(java.util.function.Consumer<java.nio.file.Path> newOnDeletion) |
static java.nio.file.Path |
toCanonicalPath(java.nio.file.Path file)
1) Convert to an absolute path without redundant path elements;
2) If the file exists, resolve any links to the underlying fille;
3) If the file does not exist, find the first ancestor that does and resolve the path from there
|
static boolean |
tryCreateDirectories(java.nio.file.Path path) |
static boolean |
tryCreateDirectory(java.nio.file.Path path) |
static boolean |
tryDelete(java.nio.file.Path file) |
static long |
tryGetLastModified(java.nio.file.Path path) |
static long |
tryGetLength(java.nio.file.Path path) |
static long |
tryGetSpace(java.nio.file.Path path,
PathUtils.IOToLongFunction<java.nio.file.FileStore> getSpace)
Returns the number of bytes (determined by the provided MethodHandle) on the specified partition.
|
static long |
tryGetSpace(java.nio.file.Path path,
PathUtils.IOToLongFunction<java.nio.file.FileStore> getSpace,
java.util.function.Consumer<java.io.IOException> orElse) |
static <T extends java.lang.Throwable,V> |
tryList(java.nio.file.Path path,
java.util.function.Function<java.util.stream.Stream<java.nio.file.Path>,java.util.stream.Stream<V>> transform,
java.util.function.IntFunction<V[]> arrayFactory,
net.openhft.chronicle.core.util.ThrowingFunction<java.io.IOException,V[],T> orElse) |
static boolean |
tryRename(java.nio.file.Path from,
java.nio.file.Path to) |
static boolean |
trySet(java.nio.file.Path path,
java.nio.file.attribute.PosixFilePermission permission,
boolean set) |
static boolean |
trySetExecutable(java.nio.file.Path path,
boolean executable) |
static boolean |
trySetLastModified(java.nio.file.Path path,
long lastModified) |
static boolean |
trySetReadable(java.nio.file.Path path,
boolean readable) |
static boolean |
trySetWritable(java.nio.file.Path path,
boolean writeable) |
public static java.nio.channels.FileChannel newReadChannel(java.nio.file.Path path) throws java.nio.file.NoSuchFileException
java.nio.file.NoSuchFileException
public static java.nio.channels.FileChannel newReadWriteChannel(java.nio.file.Path path) throws java.nio.file.NoSuchFileException
java.nio.file.NoSuchFileException
public static java.nio.channels.FileChannel newWriteOverwriteChannel(java.nio.file.Path path) throws java.nio.file.NoSuchFileException
java.nio.file.NoSuchFileException
public static java.nio.channels.FileChannel newWriteAppendChannel(java.nio.file.Path path) throws java.nio.file.NoSuchFileException
java.nio.file.NoSuchFileException
public static void setDeletionListener(java.util.function.Consumer<java.nio.file.Path> newOnDeletion)
public static java.lang.String filename(java.nio.file.Path path)
public static <T> T[] list(java.nio.file.Path path, java.util.function.Function<java.util.stream.Stream<java.nio.file.Path>,java.util.stream.Stream<T>> transform, java.util.function.IntFunction<T[]> arrayFactory)
public static <T extends java.lang.Throwable,V> V[] tryList(java.nio.file.Path path, java.util.function.Function<java.util.stream.Stream<java.nio.file.Path>,java.util.stream.Stream<V>> transform, java.util.function.IntFunction<V[]> arrayFactory, net.openhft.chronicle.core.util.ThrowingFunction<java.io.IOException,V[],T> orElse) throws T extends java.lang.Throwable
T extends java.lang.Throwable
public static void forEach(java.nio.file.Path path, java.util.function.Consumer<java.nio.file.Path> forEach)
public static void forEachRecursive(java.nio.file.Path path, java.util.function.Consumer<java.nio.file.Path> forEach)
public static long tryGetLength(java.nio.file.Path path)
public static long tryGetLastModified(java.nio.file.Path path)
public static boolean trySetLastModified(java.nio.file.Path path, long lastModified)
public static boolean trySetReadable(java.nio.file.Path path, boolean readable)
public static boolean trySetWritable(java.nio.file.Path path, boolean writeable)
public static boolean trySetExecutable(java.nio.file.Path path, boolean executable)
public static boolean trySet(java.nio.file.Path path, java.nio.file.attribute.PosixFilePermission permission, boolean set)
public static java.lang.Throwable delete(java.nio.file.Path file, java.lang.Throwable accumulate)
public static void delete(java.nio.file.Path file)
public static void deleteIfExists(java.nio.file.Path file)
public static boolean tryDelete(java.nio.file.Path file)
public static void delete(java.nio.file.Path file, @Nullable com.google.common.util.concurrent.RateLimiter rateLimiter)
public static java.lang.Throwable delete(java.nio.file.Path file, java.lang.Throwable accumulate, @Nullable com.google.common.util.concurrent.RateLimiter rateLimiter)
public static void deleteRecursive(java.nio.file.Path path)
path
- file to be deletedFSWriteError
- if any part of the tree cannot be deletedpublic static void deleteRecursive(java.nio.file.Path path, com.google.common.util.concurrent.RateLimiter rateLimiter)
path
- file to be deletedFSWriteError
- if any part of the tree cannot be deletedpublic static void deleteRecursiveOnExit(java.nio.file.Path dir)
dir
- Directory to be deletedpublic static void deleteOnExit(java.nio.file.Path file)
file
- File to be deletedpublic static boolean tryRename(java.nio.file.Path from, java.nio.file.Path to)
public static void rename(java.nio.file.Path from, java.nio.file.Path to)
public static boolean exists(java.nio.file.Path path)
public static boolean isDirectory(java.nio.file.Path path)
public static boolean isFile(java.nio.file.Path path)
public static boolean createFileIfNotExists(java.nio.file.Path path)
path
- create file if not existsjava.io.IOError
- if cannot perform the operationpublic static boolean createDirectoryIfNotExists(java.nio.file.Path path)
path
- create directory if not existsjava.io.IOError
- if cannot perform the operationpublic static boolean createDirectoriesIfNotExists(java.nio.file.Path path)
path
- create directory (and parents) if not existsjava.io.IOError
- if cannot perform the operationpublic static boolean tryCreateDirectory(java.nio.file.Path path)
path
- create directory if not exists and action can be performedpublic static boolean tryCreateDirectories(java.nio.file.Path path)
path
- create directory (and parents) if not exists and action can be performedpublic static java.nio.file.Path findExistingAncestor(java.nio.file.Path file)
public static java.nio.file.Path toCanonicalPath(java.nio.file.Path file)
public static boolean isContained(java.nio.file.Path folder, java.nio.file.Path file)
public static void runOnExitThreadsAndClear()
public static void clearOnExitThreads()
public static long tryGetSpace(java.nio.file.Path path, PathUtils.IOToLongFunction<java.nio.file.FileStore> getSpace)
This method handles large file system by returning Long.MAX_VALUE
if the number of available bytes
overflow. See JDK-8179320 for more information
path
- the partition (or a file within it)public static long tryGetSpace(java.nio.file.Path path, PathUtils.IOToLongFunction<java.nio.file.FileStore> getSpace, java.util.function.Consumer<java.io.IOException> orElse)
public static java.lang.RuntimeException propagateUnchecked(java.io.IOException ioe, java.nio.file.Path path, boolean write)
public static java.lang.RuntimeException propagateUnchecked(java.lang.String message, java.io.IOException ioe, java.nio.file.Path path, boolean write)
public static java.nio.file.NoSuchFileException propagateUncheckedOrNoSuchFileException(java.io.IOException ioe, java.nio.file.Path path, boolean write) throws java.nio.file.NoSuchFileException
java.nio.file.NoSuchFileException
public static <E extends java.io.IOException> E propagate(E ioe, java.nio.file.Path path, boolean write) throws E extends java.io.IOException
E extends java.io.IOException
Copyright © 2009- The Apache Software Foundation