Package org.apache.camel.util
Class FileUtil
- java.lang.Object
-
- org.apache.camel.util.FileUtil
-
-
Field Summary
Fields Modifier and Type Field Description static intBUFFER_SIZE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 voidcopyFile(File from, File to)Copies 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 FilegetUserDir()static booleanhasLeadingSeparator(String name)Does the name start with a leading separatorstatic booleanisAbsolute(File file)Is the given file an absolute file.static booleanisWindows()Returns true, if the OS is windowsstatic StringnormalizePath(String path)Normalizes the path to cater for Windows and other platformsstatic StringonlyExt(String name)static StringonlyExt(String name, boolean singleMode)static StringonlyName(String name)static StringonlyName(String name, boolean singleMode)static StringonlyPath(String name)Returns only the leading path (returns null if no path)static voidremoveDir(File d)static booleanrenameFile(File from, File to, boolean copyAndDeleteOnRenameFail)Renames a file.static booleanrenameFileUsingCopy(File from, File to)Rename file using copy and delete strategy.static StringstripExt(String name)static StringstripExt(String name, boolean singleMode)static StringstripFirstLeadingSeparator(String name)Strip first leading separatorstatic StringstripLeadingSeparator(String name)Strip any leading separatorsstatic StringstripPath(String name)Strips any leading pathsstatic StringstripTrailingSeparator(String name)Strip any trailing separators
-
-
-
Field Detail
-
BUFFER_SIZE
public static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getUserDir
public static File getUserDir()
-
normalizePath
public static String normalizePath(String path)
Normalizes the path to cater for Windows and other platforms
-
isWindows
public static boolean isWindows()
Returns true, if the OS is windows
-
createTempFile
public static File createTempFile(String prefix, String suffix, File parentDir) throws IOException
- Throws:
IOException
-
stripLeadingSeparator
public static String stripLeadingSeparator(String name)
Strip any leading separators
-
hasLeadingSeparator
public static boolean hasLeadingSeparator(String name)
Does the name start with a leading separator
-
stripFirstLeadingSeparator
public static String stripFirstLeadingSeparator(String name)
Strip first leading separator
-
stripTrailingSeparator
public static String stripTrailingSeparator(String name)
Strip any trailing separators
-
onlyPath
public static String onlyPath(String name)
Returns only the leading path (returns null if no path)
-
compactPath
public static String compactPath(String path)
Compacts a path by stacking it and reducing .., and uses OS specific file separators (egFile.separator).
-
compactPath
public static String compactPath(String path, char separator)
Compacts a path by stacking it and reducing .., and uses the given separator.
-
compactPath
public static String compactPath(String path, String separator)
Compacts a file path by stacking it and reducing .., and uses the given separator.
-
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
public static boolean renameFileUsingCopy(File from, File to) throws IOException
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
public static void copyFile(File from, File to) throws IOException
Copies the file- Parameters:
from- the source fileto- the destination file- Throws:
IOException- If an I/O error occurs during copy operation
-
deleteFile
public static boolean deleteFile(File file)
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
public static boolean isAbsolute(File file)
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
public static boolean createNewFile(File file) throws IOException
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
-
-