Package org.omegat.util
Class FileUtil
java.lang.Object
org.omegat.util.FileUtil
Files processing utilities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic classComparator to sort the tm/ folder alphabetically, but always put tm/enforce and tm/auto results before other similar % matches. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringabsoluteForSystem(String path) Converts Windows absolute path into current system's absolute path.static FilebackupFile(File original) Create file backup with datetime suffix.buildFileList(File rootDir, boolean recursive) Returns a list of all files under the root directory by absolute path.static booleancheckFileInclude(String filePath, Pattern[] includes, Pattern[] excludes) static Pattern[]compileFileMasks(List<String> masks) static StringcomputeRelativePath(File rootDir, File file) Compute relative path of file.static voidcopyFilesTo(File destination, File[] toCopy, FileUtil.ICollisionCallback onCollision) Copy a collection of files to a destination.static voidcopyFileWithEolConversion(File inFile, File outFile, Charset charset) Copy file and create output directory if need.static StringexpandTildeHomeDir(String path) Expand tilde(~) in first character in path string.findFiles(File dir, FileFilter filter) Find files in subdirectories.findFiles(File dir, FileFilter filter, Comparator<File> comp) static StringgetBackupFilename(File original) Generates a name for the file to be backuped, in the form of[original_name].yyyyMMddHHmm.bak.static StringRead a file to determine its end-of-line character(s).static FilegetRecentBackup(File originalFile) Get most recent backup file path.getUniqueNames(List<String> paths) Given a list of paths, return a list of filenames (a laFile.getName()) plus the minimum number of parent path segments required to make each filename unique within the result list.static booleanCheck if file is in specified path.static booleanisRelative(String path) Checks if path starts with possible root on the Linux, MacOS, Windows.static voidremoveOldBackups(File originalFile, int maxBackups) Removes older backups to be under specified number of files.static voidRenames file, with checking errors and 3 seconds retry against external programs (like antivirus or TortoiseSVN) locking.
-
Field Details
-
RENAME_RETRY_TIMEOUT
public static final long RENAME_RETRY_TIMEOUT- See Also:
-
-
Method Details
-
getRecentBackup
Get most recent backup file path.- Parameters:
originalFile- target original file name.
-
removeOldBackups
Removes older backups to be under specified number of files.- Parameters:
originalFile- target original file name.maxBackups- maximum number of back up files.
-
backupFile
Create file backup with datetime suffix.- Parameters:
original- a file to copy as backup file.- Returns:
- Backup file.
-
getBackupFilename
Generates a name for the file to be backuped, in the form of[original_name].yyyyMMddHHmm.bak.- Parameters:
original- the file to be backuped- Returns:
- the name of the backuped file
-
rename
Renames file, with checking errors and 3 seconds retry against external programs (like antivirus or TortoiseSVN) locking.- Throws:
IOException
-
copyFileWithEolConversion
public static void copyFileWithEolConversion(File inFile, File outFile, Charset charset) throws IOException Copy file and create output directory if need. EOL will be converted into target-specific or into platform-specific if target doesn't exist.- Throws:
IOException
-
getEOL
Read a file to determine its end-of-line character(s). If neither '\n' nor '\r' are present in the file then it will return null.- Parameters:
file-charset-- Returns:
- The EOL character(s) as a string, or null if not detectable
- Throws:
IOException
-
findFiles
Find files in subdirectories.- Parameters:
dir- directory to start findfilter- filter for found files- Returns:
- list of filtered found files
-
findFiles
-
computeRelativePath
Compute relative path of file.- Parameters:
rootDir- root directoryfile- file- Returns:
- Throws:
IOException
-
isInPath
Check if file is in specified path. -
expandTildeHomeDir
Expand tilde(~) in first character in path string.- Parameters:
path- path string- Returns:
- expanded path string
-
copyFilesTo
public static void copyFilesTo(File destination, File[] toCopy, FileUtil.ICollisionCallback onCollision) throws IOException Copy a collection of files to a destination. Recursively copies contents of directories while preserving relative paths. Provide anFileUtil.ICollisionCallbackto determine what to do with files with conflicting names; they will be overwritten if the callback is null.- Parameters:
destination- Directory to copy totoCopy- Files to copyonCollision- Callback that determines what to do in case files with the same name already exist- Throws:
IOException
-
isRelative
Checks if path starts with possible root on the Linux, MacOS, Windows. -
absoluteForSystem
Converts Windows absolute path into current system's absolute path. It required for conversion like 'C:\zzz' into '/zzz' for be real absolute in Linux. -
buildFileList
Returns a list of all files under the root directory by absolute path.- Throws:
IOException
-
buildRelativeFilesList
public static List<String> buildRelativeFilesList(File rootDir, List<String> includes, List<String> excludes) throws IOException - Throws:
IOException
-
checkFileInclude
-
compileFileMasks
-
getUniqueNames
Given a list of paths, return a list of filenames (a laFile.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)
/).- Parameters:
paths- A list of paths- Returns:
- A list of minimal unique paths
-