Object FilesUtils
-
- All Implemented Interfaces:
public class FilesUtilsObject with io related utility methods in the style of java.nio.file.Files.
-
-
Field Summary
Fields Modifier and Type Field Description public final static FilesUtilsINSTANCE
-
Method Summary
Modifier and Type Method Description final Sequence<Path>walkUpwards(Path path, Function1<Path, Boolean> until)Returns a sequence yielding every path starting with the passed path and walking up to its ancestors until the given until condition is met. final Sequence<Path>walkUpwards(Path path, Path until)Returns a sequence yielding every path starting with the passed path until the given until (inclusive) is reached. final Sequence<Path>getLeafDirectories(Path path, Boolean sort)Returns all leaf directories of the given path, optionally sorted by alphanumeric order (if sort is set to true, which is the default). final UnitdeleteRecursivelyIfExisting(Path path)Deletes the given path recursively, if existing. final UnitcopyFilesFromDirectory(Path source, Path dest)Copies all files from the given source directory to the given dest directory. final BooleanisDirectoryEmpty(Path path)Checks whether the directory at the given path is empty. final PathifExists(Path path)Returns the given path if it exists or null otherwise. final PathvalidateExistence(Path path)Validates if a file or directory exists at the given path and returns it. final <T extends Any> TuseBufferedReader(Path path, Function1<BufferedReader, T> block)Creates a new BufferedReader for the given path and executes block with improved error handling. final ByteArrayreadAllBytes(Path path)Reads all bytes at the given path with improved error handling. final List<String>readAllLines(Path path)Reads all lines at the given path with improved error handling. -
-
Method Detail
-
walkUpwards
final Sequence<Path> walkUpwards(Path path, Function1<Path, Boolean> until)
Returns a sequence yielding every path starting with the passed path and walking up to its ancestors until the given until condition is met. The default is when the current path has no parent.
-
walkUpwards
final Sequence<Path> walkUpwards(Path path, Path until)
Returns a sequence yielding every path starting with the passed path until the given until (inclusive) is reached.
-
getLeafDirectories
final Sequence<Path> getLeafDirectories(Path path, Boolean sort)
Returns all leaf directories of the given path, optionally sorted by alphanumeric order (if sort is set to true, which is the default).
The given path itself is never yielded; only descendant directories that have no further subdirectories qualify as leaves.
-
deleteRecursivelyIfExisting
final Unit deleteRecursivelyIfExisting(Path path)
Deletes the given path recursively, if existing.
-
copyFilesFromDirectory
final Unit copyFilesFromDirectory(Path source, Path dest)
-
isDirectoryEmpty
final Boolean isDirectoryEmpty(Path path)
Checks whether the directory at the given path is empty.
-
validateExistence
final Path validateExistence(Path path)
Validates if a file or directory exists at the given path and returns it.
-
useBufferedReader
final <T extends Any> T useBufferedReader(Path path, Function1<BufferedReader, T> block)
Creates a new BufferedReader for the given path and executes block with improved error handling.
-
readAllBytes
final ByteArray readAllBytes(Path path)
Reads all bytes at the given path with improved error handling.
-
readAllLines
final List<String> readAllLines(Path path)
Reads all lines at the given path with improved error handling.
-
-
-
-