Package org.savantbuild.io
Class FileTools
java.lang.Object
org.savantbuild.io.FileTools
File utilities.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PathcreateTempPath(String prefix, String suffix, boolean deleteOnExit) Creates a temporary file.extensionFilter(String extension) Returns a Predicate that returns true if the Path has the given extension.extensionMapper(String original, String target) Returns a Function that maps a source path to a target path by changing the extension of the Path.Determines the files that have been modified with respect to the given output directory.static voidPrunes the given path.static IntegertoHexMode(Set<PosixFilePermission> permissions) Converts the file permissions to a hex permission value.static inttoMode(int hex) Converts a hex value to a POSIX mode.static inttoMode(Collection<PosixFilePermission> permissions) Converts the file permissions of this FileInfo to a POSIX bit mapped mode.static PathConverts the object to a Path.static Set<PosixFilePermission>toPosixPermissions(int mode) Converts the POSIX bit mapped file mode integer to a set of PosixFilePermissions.static voidUpdates the last modified timestamp of each of the given Paths.
-
Constructor Details
-
FileTools
public FileTools()
-
-
Method Details
-
createTempPath
public static Path createTempPath(String prefix, String suffix, boolean deleteOnExit) throws IOException Creates a temporary file.- Parameters:
prefix- The prefix for the temporary file.suffix- The suffix for the temporary file.deleteOnExit- If the file should be deleted when the JVM exits.- Returns:
- The Path of the temporary file.
- Throws:
IOException- If the create fails.
-
extensionFilter
Returns a Predicate that returns true if the Path has the given extension.- Parameters:
extension- The extension.- Returns:
- The Predicate.
-
extensionMapper
Returns a Function that maps a source path to a target path by changing the extension of the Path.- Parameters:
original- The original extension.target- The target extension.- Returns:
- The Function.
-
modifiedFiles
public static List<Path> modifiedFiles(Path sourceDir, Path outputDir, Predicate<Path> filter, Function<Path, Path> mapper) throws IllegalStateExceptionDetermines the files that have been modified with respect to the given output directory.- Parameters:
sourceDir- The source directory to walk.outputDir- The output directory to compare against.filter- A predicate that reduces the files that are compared. This should return true for files that are compared and false for those that aren't.mapper- A function that maps a source file to a target file.- Returns:
- The list of modified files.
- Throws:
IllegalStateException- If the code throws an IOException it is wrapped into an IllegalStateException.
-
prune
Prunes the given path. If the path is a directory, this deletes everything underneath it, but does not traverse across symbolic links, it simply deletes the link. If the path is a file, it is deleted. If the path is a symbolic link, it is unlinked.- Parameters:
path- The path to delete.- Throws:
IOException- If the prune failed for any reason. This might indicate that the prune was only partially successful.
-
toHexMode
Converts the file permissions to a hex permission value.- Parameters:
permissions- The set of POSIX file permissions.- Returns:
- The hex value.
-
toMode
Converts the file permissions of this FileInfo to a POSIX bit mapped mode. The bit map looks like this:
1_000_000_001_000_000
The first bit is always set. The next three bits are the set UID bits, the next 3 bits are the set GID bits. The next three bits are the owner permissions (read, write, execute), then the group permissions and finally the user permissions.
- Parameters:
permissions- The POSIX file permissions.- Returns:
- The POSIX mode bit map as an integer.
-
toMode
public static int toMode(int hex) Converts a hex value to a POSIX mode. This allows you to use a hex lik 0x777 to represent rwx-rwx-rwx.- Parameters:
hex- The hex mode.- Returns:
- The POSIX mode.
-
toPath
Converts the object to a Path.- Parameters:
object- The object.- Returns:
- The object as a path.
-
toPosixPermissions
Converts the POSIX bit mapped file mode integer to a set of PosixFilePermissions. The bit map looks like this:
1_000_000_001_000_000
The first bit is always set. The next three bits are the set UID bits, the next 3 bits are the set GID bits. The next three bits are the owner permissions (read, write, execute), then the group permissions and finally the user permissions.
- Parameters:
mode- The POSIX bit mapped permissions.- Returns:
- The POSIX mode bit map as an integer.
-
touch
Updates the last modified timestamp of each of the given Paths. This effectively "touches" each Path.- Parameters:
paths- The Paths to touch.- Throws:
IOException- If the update fails.
-