public final class SafeFiles extends Object
Path that avoid leaking file handles.| Modifier and Type | Method and Description |
|---|---|
static <T> T |
lines(Path file,
Function<Stream<String>,T> function)
Streams the lines in the specified file using UTF-8.
|
static List<String> |
linesAll(Path file)
Loads the specified file as a list of lines using UTF-8.
|
static <T> T |
list(Path dir,
Function<Stream<Path>,T> function)
Streams the elements in the specified directory without recursing into subdirectories.
|
static List<Path> |
listAll(Path dir)
Lists the elements in the specified directory without recursing into subdirectories.
|
static <T> T |
walk(Path dir,
int maxDepth,
Function<Stream<Path>,T> function,
FileVisitOption... options)
Lists the elements in the specified directory, recursing depth-first into subdirectories.
|
static List<Path> |
walkAll(Path dir)
Lists the elements in the specified directory, recursing depth-first into subdirectories.
|
static List<Path> |
walkAll(Path dir,
int maxDepth,
FileVisitOption... options)
Lists the elements in the specified directory, recursing depth-first into subdirectories.
|
public static List<Path> listAll(Path dir)
This is a safe wrapper for Files.list(Path).
dir - the path to list filesSecurityException - if access is rejected by a security managerUncheckedIOException - if an IO error occurspublic static <T> T list(Path dir, Function<Stream<Path>,T> function)
This is a safe wrapper for Files.list(Path).
T - the type of the resultdir - the path to list filesfunction - the function to apply to the streamSecurityException - if access is rejected by a security managerUncheckedIOException - if an IO error occurspublic static List<Path> walkAll(Path dir)
This is a safe wrapper for Files.walk(Path, FileVisitOption...).
It recurses into all subdirectories and does not follow links.
dir - the start path to list files fromIllegalArgumentException - if maxDepth is negativeSecurityException - if access is rejected by a security managerUncheckedIOException - if an IO error occurspublic static List<Path> walkAll(Path dir, int maxDepth, FileVisitOption... options)
This is a safe wrapper for Files.walk(Path, int, FileVisitOption...).
dir - the start path to list files frommaxDepth - the maximum depth to recurse to, one for one-level and so onoptions - the optionsIllegalArgumentException - if maxDepth is negativeSecurityException - if access is rejected by a security managerUncheckedIOException - if an IO error occurspublic static <T> T walk(Path dir, int maxDepth, Function<Stream<Path>,T> function, FileVisitOption... options)
This is a safe wrapper for Files.walk(Path, int, FileVisitOption...).
T - the type of the resultdir - the start path to list files frommaxDepth - the maximum depth to recurse to, one for one-level and so onfunction - the function to apply to the streamoptions - the optionsIllegalArgumentException - if maxDepth is negativeSecurityException - if access is rejected by a security managerUncheckedIOException - if an IO error occurspublic static List<String> linesAll(Path file)
This is a safe wrapper for Files.lines(Path).
file - the path to readSecurityException - if access is rejected by a security managerUncheckedIOException - if an IO error occurspublic static <T> T lines(Path file, Function<Stream<String>,T> function)
This is a safe wrapper for Files.lines(Path).
T - the type of the resultfile - the path to readfunction - the function to apply to the streamSecurityException - if access is rejected by a security managerUncheckedIOException - if an IO error occursCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.