- java.lang.Object
-
- io.helidon.build.util.FileUtils
-
public final class FileUtils extends Object
File utilities.
-
-
Field Summary
Fields Modifier and Type Field Description static PathCURRENT_JAVA_HOME_DIRThe Java Home directory for the running JVM.static PathWORKING_DIRThe working directory.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PathassertDir(Path directory)Assert that the given path exists and is a directory.static PathassertExists(Path path)Assert that the given path exists.static PathassertFile(Path file)Assert that the given path exists and is a file.static PathdeleteDirectory(Path directory)Deletes the given directory if it exists.static PathensureDirectory(Path path, FileAttribute<?>... attrs)Ensure that the given path is an existing directory, creating it if required.static StringfileName(Path file)Returns the file name of the given file, as a string.static PathfromWorking(Path path)Returns the relative path from the working directory for the given path, if possible.static longlastModifiedTime(Path file)Returns the last modified time of the given file, in seconds.static List<Path>list(Path directory)List all files and directories in the given directory.static List<Path>listFiles(Path directory, Predicate<String> fileNameFilter)List all files in the given directory that match the given filter.static longsizeOf(Path path)Returns the total size of all files in the given path, including subdirectories.
-
-
-
Method Detail
-
fromWorking
public static Path fromWorking(Path path)
Returns the relative path from the working directory for the given path, if possible.- Parameters:
path- The path.- Returns:
- The relative path or the original if it is not within the working directory.
-
ensureDirectory
public static Path ensureDirectory(Path path, FileAttribute<?>... attrs)
Ensure that the given path is an existing directory, creating it if required.- Parameters:
path- The path.attrs- The attributes.- Returns:
- The normalized, absolute directory path.
-
listFiles
public static List<Path> listFiles(Path directory, Predicate<String> fileNameFilter)
List all files in the given directory that match the given filter. Does not recurse.- Parameters:
directory- The directory.fileNameFilter- The filter.- Returns:
- The normalized, absolute file paths.
-
list
public static List<Path> list(Path directory)
List all files and directories in the given directory. Does not recurse.- Parameters:
directory- The directory.- Returns:
- The normalized, absolute file paths.
-
assertDir
public static Path assertDir(Path directory)
Assert that the given path exists and is a directory.- Parameters:
directory- The directory.- Returns:
- The normalized, absolute directory path.
- Throws:
IllegalArgumentException- If the path does not exist or is not a directory.
-
assertFile
public static Path assertFile(Path file)
Assert that the given path exists and is a file.- Parameters:
file- The file.- Returns:
- The normalized, absolute file path.
- Throws:
IllegalArgumentException- If the path does not exist or is not a file.
-
assertExists
public static Path assertExists(Path path)
Assert that the given path exists.- Parameters:
path- The path.- Returns:
- The normalized, absolute path.
- Throws:
IllegalArgumentException- If the path does not exist.
-
deleteDirectory
public static Path deleteDirectory(Path directory) throws IOException
Deletes the given directory if it exists.- Parameters:
directory- The directory.- Returns:
- The directory.
- Throws:
IOException- If an error occurs.
-
sizeOf
public static long sizeOf(Path path)
Returns the total size of all files in the given path, including subdirectories.- Parameters:
path- The path. May be a file or directory.- Returns:
- The size, in bytes.
- Throws:
UncheckedIOException- If an error occurs.
-
lastModifiedTime
public static long lastModifiedTime(Path file)
Returns the last modified time of the given file, in seconds.- Parameters:
file- The file.- Returns:
- The last modified time.
-
-