public class FileTools
extends java.lang.Object
Constructor and Description |
---|
FileTools() |
Modifier and Type | Method and Description |
---|---|
static java.nio.file.Path |
createTempPath(java.lang.String prefix,
java.lang.String suffix,
boolean deleteOnExit)
Creates a temporary file.
|
static java.util.function.Predicate<java.nio.file.Path> |
extensionFilter(java.lang.String extension)
Returns a Predicate that returns true if the Path has the given extension.
|
static java.util.function.Function<java.nio.file.Path,java.nio.file.Path> |
extensionMapper(java.lang.String original,
java.lang.String target)
Returns a Function that maps a source path to a target path by changing the extension of the Path.
|
static java.util.List<java.nio.file.Path> |
modifiedFiles(java.nio.file.Path sourceDir,
java.nio.file.Path outputDir,
java.util.function.Predicate<java.nio.file.Path> filter,
java.util.function.Function<java.nio.file.Path,java.nio.file.Path> mapper)
Determines the files that have been modified with respect to the given output directory.
|
static void |
prune(java.nio.file.Path path)
Prunes the given path.
|
static java.lang.Integer |
toHexMode(java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions)
Converts the file permissions to a hex permission value.
|
static int |
toMode(java.util.Collection<java.nio.file.attribute.PosixFilePermission> permissions)
Converts the file permissions of this FileInfo to a POSIX bit mapped mode.
|
static int |
toMode(int hex)
Converts a hex value to a POSIX mode.
|
static java.nio.file.Path |
toPath(java.lang.Object object)
Converts the object to a Path.
|
static java.util.Set<java.nio.file.attribute.PosixFilePermission> |
toPosixPermissions(int mode)
Converts the POSIX bit mapped file mode integer to a set of PosixFilePermissions.
|
static void |
touch(java.nio.file.Path... paths)
Updates the last modified timestamp of each of the given Paths.
|
public static java.nio.file.Path createTempPath(java.lang.String prefix, java.lang.String suffix, boolean deleteOnExit) throws java.io.IOException
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.java.io.IOException
- If the create fails.public static java.util.function.Predicate<java.nio.file.Path> extensionFilter(java.lang.String extension)
extension
- The extension.public static java.util.function.Function<java.nio.file.Path,java.nio.file.Path> extensionMapper(java.lang.String original, java.lang.String target)
original
- The original extension.target
- The target extension.public static java.util.List<java.nio.file.Path> modifiedFiles(java.nio.file.Path sourceDir, java.nio.file.Path outputDir, java.util.function.Predicate<java.nio.file.Path> filter, java.util.function.Function<java.nio.file.Path,java.nio.file.Path> mapper) throws java.lang.IllegalStateException
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.java.lang.IllegalStateException
- If the code throws an IOException it is wrapped into an IllegalStateException.public static void prune(java.nio.file.Path path) throws java.io.IOException
path
- The path to delete.java.io.IOException
- If the prune failed for any reason. This might indicate that the prune was only partially
successful.public static java.lang.Integer toHexMode(java.util.Set<java.nio.file.attribute.PosixFilePermission> permissions)
permissions
- The set of POSIX file permissions.public static int toMode(java.util.Collection<java.nio.file.attribute.PosixFilePermission> permissions)
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.
permissions
- The POSIX file permissions.public static int toMode(int hex)
hex
- The hex mode.public static java.nio.file.Path toPath(java.lang.Object object)
object
- The object.public static java.util.Set<java.nio.file.attribute.PosixFilePermission> toPosixPermissions(int mode)
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.
mode
- The POSIX bit mapped permissions.public static void touch(java.nio.file.Path... paths) throws java.io.IOException
paths
- The Paths to touch.java.io.IOException
- If the update fails.