Package org.apache.camel.util
Class FileUtil
java.lang.Object
org.apache.camel.util.FileUtil
File utilities.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcompactPath(String path) Compacts a path by stacking it and reducing .., and uses OS specific file separators (egFile.separator).static StringcompactPath(String path, char separator) Compacts a path by stacking it and reducing .., and uses the given separator.static StringcompactPath(String path, String separator) Compacts a file path by stacking it and reducing .., and uses the given separator.static voidCopies the filestatic booleancreateNewFile(File file) Creates a new file.static FilecreateTempFile(String prefix, String suffix, File parentDir) static booleandeleteFile(File file) Deletes the file.static Filestatic booleanhasLeadingSeparator(String name) Does the name start with a leading separatorstatic booleanisAbsolute(File file) Is the given file an absolute file.static booleanReturns true, if the OS is windowsstatic StringnormalizePath(String path) Normalizes the path to cater for Windows and other platformsstatic Stringstatic Stringstatic Stringstatic Stringstatic StringReturns only the leading path (returns null if no path)static voidstatic booleanrenameFile(File from, File to, boolean copyAndDeleteOnRenameFail) Renames a file.static booleanrenameFileUsingCopy(File from, File to) Rename file using copy and delete strategy.static Stringstatic Stringstatic StringStrip first leading separatorstatic StringstripLeadingSeparator(String name) Strip any leading separatorsstatic StringStrips any leading pathsstatic StringstripTrailingSeparator(String name) Strip any trailing separators
-
Field Details
-
BUFFER_SIZE
- See Also:
-
-
Method Details
-
getUserDir
-
normalizePath
Normalizes the path to cater for Windows and other platforms -
isWindows
Returns true, if the OS is windows -
createTempFile
- Throws:
IOException
-
stripLeadingSeparator
Strip any leading separators -
hasLeadingSeparator
Does the name start with a leading separator -
stripFirstLeadingSeparator
Strip first leading separator -
stripTrailingSeparator
Strip any trailing separators -
stripPath
Strips any leading paths -
stripExt
-
stripExt
-
onlyExt
-
onlyExt
-
onlyPath
Returns only the leading path (returns null if no path) -
onlyName
-
onlyName
-
compactPath
Compacts a path by stacking it and reducing .., and uses OS specific file separators (egFile.separator). -
compactPath
Compacts a path by stacking it and reducing .., and uses the given separator. -
compactPath
Compacts a file path by stacking it and reducing .., and uses the given separator. -
removeDir
-
renameFile
public static boolean renameFile(File from, File to, boolean copyAndDeleteOnRenameFail) throws IOException Renames a file.- Parameters:
from- the from fileto- the to filecopyAndDeleteOnRenameFail- whether to fallback and do copy and delete, if renameTo fails- Returns:
- true if the file was renamed, otherwise false
- Throws:
IOException- is thrown if error renaming file
-
renameFileUsingCopy
Rename file using copy and delete strategy. This is primarily used in environments where the regular rename operation is unreliable.- Parameters:
from- the file to be renamedto- the new target file- Returns:
- true if the file was renamed successfully, otherwise false
- Throws:
IOException- If an I/O error occurs during copy or delete operations.
-
copyFile
Copies the file- Parameters:
from- the source fileto- the destination file- Throws:
IOException- If an I/O error occurs during copy operation
-
deleteFile
Deletes the file. This implementation will attempt to delete the file up till three times with one second delay, which can mitigate problems on deleting files on some platforms such as Windows.- Parameters:
file- the file to delete
-
isAbsolute
Is the given file an absolute file. Will also work around issue on Windows to consider files on Windows starting with a \ as absolute files. This makes the logic consistent across all OS platforms.- Parameters:
file- the file- Returns:
- true if its an absolute path, false otherwise.
-
createNewFile
Creates a new file.- Parameters:
file- the file- Returns:
- true if created a new file, false otherwise
- Throws:
IOException- is thrown if error creating the new file
-