Class PathUtil
java.lang.Object
es.uvigo.esei.sing.textproc.step.util.PathUtil
public final class PathUtil extends java.lang.Object
This class contains static utility methods for manipulating filesystem
objects that don't belong to the responsibilities of a single class.
- Author:
- Alejandro González García
-
Constructor Summary
Constructors Constructor Description PathUtil()
-
Method Summary
Modifier and Type Method Description static void
deletePathRecursively(@NonNull java.nio.file.Path root)
Attempts a best effort to clean up the file tree whose root is at the specified path (that is, all the files and directories inside a directory, likerm -rf
does on Unix systems).static long
getTotalPathSize(@NonNull java.nio.file.Path root)
Returns an approximation to the total disk space consumed by a file tree whose root is at the specified path (in other words, the total disk space consumed by all the files inside a directory, including files in subdirectories).
-
Constructor Details
-
Method Details
-
deletePathRecursively
Attempts a best effort to clean up the file tree whose root is at the specified path (that is, all the files and directories inside a directory, likerm -rf
does on Unix systems). Any I/O error that occurs is silently discarded.- Parameters:
root
- The root location of file system (sub)tree that will be deleted.- Throws:
java.lang.IllegalArgumentException
- Ifroot
isnull
.
-
getTotalPathSize
Returns an approximation to the total disk space consumed by a file tree whose root is at the specified path (in other words, the total disk space consumed by all the files inside a directory, including files in subdirectories).If an I/O error occurs while processing a file or directory, which can be caused, for instance, by insufficient permissions to read it, it won't be counted for the total. On the other hand, even if no I/O error occurs, it is not guaranteed that the resulting number is the exact total size of the files in the file system because of transparent compression, sparse files and so on. Also, symbolic links are resolved.
- Parameters:
root
- The root location of file system (sub)tree whose size will be computed.- Returns:
- The total approximate size of the disk space consumed by the (sub)tree, in bytes.
- Throws:
java.lang.IllegalArgumentException
- Ifroot
isnull
.
-