public final class FileUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
FileUtil.ICollisionCallback |
static class |
FileUtil.TmFileComparator
Comparator to sort the tm/ folder alphabetically, but always put tm/enforce
and tm/auto results before other similar % matches.
|
Modifier and Type | Field and Description |
---|---|
static long |
RENAME_RETRY_TIMEOUT |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
absoluteForSystem(java.lang.String path,
Platform.OsType currentOsType)
Converts Windows absolute path into current system's absolute path.
|
static java.io.File |
backupFile(java.io.File original)
Create file backup with datetime suffix.
|
static java.util.List<java.io.File> |
buildFileList(java.io.File rootDir,
boolean recursive)
Returns a list of all files under the root directory by absolute path.
|
static java.util.List<java.lang.String> |
buildRelativeFilesList(java.io.File rootDir,
java.util.List<java.lang.String> includes,
java.util.List<java.lang.String> excludes) |
static boolean |
checkFileInclude(java.lang.String filePath,
java.util.regex.Pattern[] includes,
java.util.regex.Pattern[] excludes) |
static java.util.regex.Pattern[] |
compileFileMasks(java.util.List<java.lang.String> masks) |
static java.lang.String |
computeRelativePath(java.io.File rootDir,
java.io.File file)
Compute relative path of file.
|
static void |
copyFilesTo(java.io.File destination,
java.io.File[] toCopy,
FileUtil.ICollisionCallback onCollision)
Copy a collection of files to a destination.
|
static void |
copyFileWithEolConversion(java.io.File inFile,
java.io.File outFile,
java.nio.charset.Charset charset)
Copy file and create output directory if need.
|
static java.util.List<java.io.File> |
findFiles(java.io.File dir,
java.io.FileFilter filter)
Find files in subdirectories.
|
static java.lang.String |
getEOL(java.io.File file,
java.nio.charset.Charset charset)
Read a file to determine its end-of-line character(s).
|
static java.util.List<java.lang.String> |
getUniqueNames(java.util.List<java.lang.String> paths)
Given a list of paths, return a list of filenames (a la
File.getName() ) plus the minimum number of parent
path segments required to make each filename unique within the result list. |
static boolean |
isInPath(java.io.File path,
java.io.File tmxFile)
Check if file is in specified path.
|
static boolean |
isRelative(java.lang.String path)
Checks if path starts with possible root on the Linux, MacOS, Windows.
|
static void |
removeOldBackups(java.io.File originalFile,
int maxBackups)
Removes old backups so that only 10 last are there.
|
static void |
rename(java.io.File from,
java.io.File to)
Renames file, with checking errors and 3 seconds retry against external programs (like antivirus or
TortoiseSVN) locking.
|
public static final long RENAME_RETRY_TIMEOUT
public static void removeOldBackups(java.io.File originalFile, int maxBackups)
public static java.io.File backupFile(java.io.File original) throws java.io.IOException
java.io.IOException
public static void rename(java.io.File from, java.io.File to) throws java.io.IOException
java.io.IOException
public static void copyFileWithEolConversion(java.io.File inFile, java.io.File outFile, java.nio.charset.Charset charset) throws java.io.IOException
java.io.IOException
public static java.lang.String getEOL(java.io.File file, java.nio.charset.Charset charset) throws java.io.IOException
file
- charset
- java.io.IOException
public static java.util.List<java.io.File> findFiles(java.io.File dir, java.io.FileFilter filter)
dir
- directory to start findfilter
- filter for found filespublic static java.lang.String computeRelativePath(java.io.File rootDir, java.io.File file) throws java.io.IOException
rootDir
- root directoryfile
- filejava.io.IOException
public static boolean isInPath(java.io.File path, java.io.File tmxFile)
public static void copyFilesTo(java.io.File destination, java.io.File[] toCopy, FileUtil.ICollisionCallback onCollision) throws java.io.IOException
FileUtil.ICollisionCallback
to determine
what to do with files with conflicting names; they will be overwritten if the callback is null.destination
- Directory to copy totoCopy
- Files to copyonCollision
- Callback that determines what to do in case files with the same name
already existjava.io.IOException
public static boolean isRelative(java.lang.String path)
public static java.lang.String absoluteForSystem(java.lang.String path, Platform.OsType currentOsType)
public static java.util.List<java.io.File> buildFileList(java.io.File rootDir, boolean recursive) throws java.io.IOException
java.io.IOException
public static java.util.List<java.lang.String> buildRelativeFilesList(java.io.File rootDir, java.util.List<java.lang.String> includes, java.util.List<java.lang.String> excludes) throws java.io.IOException
java.io.IOException
public static boolean checkFileInclude(java.lang.String filePath, java.util.regex.Pattern[] includes, java.util.regex.Pattern[] excludes)
public static java.util.regex.Pattern[] compileFileMasks(java.util.List<java.lang.String> masks)
public static java.util.List<java.lang.String> getUniqueNames(java.util.List<java.lang.String> paths)
File.getName()
) plus the minimum number of parent
path segments required to make each filename unique within the result list. E.g.
[foo/bar.txt, foo/baz.txt] -> [bar.txt, baz.txt]
[foo/bar/baz.txt, foo/fop/baz.txt] -> [bar/baz.txt, fop/baz.txt]
[foo/bar/baz/fop.txt, foo/buz/baz/fop.txt] -> [bar/baz/fop.txt, buz/baz/fop.txt]
[foo.txt, foo.txt] -> [foo.txt, foo.txt]
(actual duplicates are unmodified)
/
).paths
- A list of paths