public class FileMisc extends Object
Miscellaneous utilties for copying files around.
| Constructor and Description |
|---|
FileMisc() |
| Modifier and Type | Method and Description |
|---|---|
static void |
cleanDir(File dirToRemove)
Deletes the given file or directory if it exists, then creates a fresh directory in its place.
|
static void |
concat(Iterable<File> toMerge,
File dst)
Concats the first files and writes them to the last file.
|
static boolean |
containsExecutablePermission(Set<PosixFilePermission> permissions)
Returns true if any of the bits contain the executable permission.
|
static void |
copyFile(File srcFile,
File dstFile,
String... toReplace)
Copies from src to dst and performs a simple copy-replace templating operation along the way.
|
static void |
flatten(File dirToRemove)
Flattens a single directory (moves its children to be its peers, then deletes the given directory.
|
static String |
toOctalFileMode(Set<PosixFilePermission> permissions)
Converts a set of
PosixFilePermission to chmod-style octal file mode. |
static int |
toOctalFileModeInt(Set<PosixFilePermission> permissions)
Converts a set of
PosixFilePermission to chmod-style octal file mode. |
static String |
toUnixNewline(String input)
Enforces unix newlines on the given string.
|
public static String toUnixNewline(String input)
Enforces unix newlines on the given string.
public static void copyFile(File srcFile, File dstFile, String... toReplace) throws IOException
Copies from src to dst and performs a simple copy-replace templating operation along the way.
copyFile(src, dst,
"%username%", "lskywalker"
"%firstname%", "Luke",
"%lastname%", "Skywalker");
IOExceptionpublic static void cleanDir(File dirToRemove) throws IOException
Deletes the given file or directory if it exists, then creates a fresh directory in its place.
IOExceptionpublic static void flatten(File dirToRemove) throws IOException
Flattens a single directory (moves its children to be its peers, then deletes the given directory.
before:
root/
toFlatten/
child1
child2
flatten("root/toFlatten")
after:
root/
child1
child2
IOExceptionpublic static void concat(Iterable<File> toMerge, File dst) throws IOException
Concats the first files and writes them to the last file.
IOExceptionpublic static int toOctalFileModeInt(Set<PosixFilePermission> permissions)
Converts a set of PosixFilePermission to chmod-style octal file mode.
public static String toOctalFileMode(Set<PosixFilePermission> permissions)
Converts a set of PosixFilePermission to chmod-style octal file mode.
public static boolean containsExecutablePermission(Set<PosixFilePermission> permissions)
Returns true if any of the bits contain the executable permission.