org.apache.camel.util
Class FileUtil

java.lang.Object
  extended by org.apache.camel.util.FileUtil

public final class FileUtil
extends java.lang.Object

File utilities


Field Summary
static int BUFFER_SIZE
           
 
Method Summary
static java.lang.String compactPath(java.lang.String path)
          Compacts a path by stacking it and reducing ..
static void copyFile(java.io.File from, java.io.File to)
           
static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix)
           
static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix, java.io.File parentDir)
           
static boolean deleteFile(java.io.File file)
           
static boolean hasLeadingSeparator(java.lang.String name)
          Does the name start with a leading separator
static boolean isAbsolute(java.io.File file)
          Is the given file an absolute file.
static boolean isWindows()
           
static java.lang.String normalizePath(java.lang.String path)
          Normalizes the path to cater for Windows and other platforms
static java.lang.String onlyPath(java.lang.String name)
          Returns only the leading path (returns null if no path)
static boolean renameFile(java.io.File from, java.io.File to)
          Renames a file.
static boolean renameFile(java.io.File from, java.io.File to, boolean copyAndDeleteOnRenameFail)
          Renames a file.
static java.lang.String stripExt(java.lang.String name)
           
static java.lang.String stripFirstLeadingSeparator(java.lang.String name)
          Strip first leading separator
static java.lang.String stripLeadingSeparator(java.lang.String name)
          Strip any leading separators
static java.lang.String stripPath(java.lang.String name)
          Strips any leading paths
static java.lang.String stripTrailingSeparator(java.lang.String name)
          Strip any trailing separators
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFFER_SIZE

public static final int BUFFER_SIZE
See Also:
Constant Field Values
Method Detail

normalizePath

public static java.lang.String normalizePath(java.lang.String path)
Normalizes the path to cater for Windows and other platforms


isWindows

public static boolean isWindows()

createTempFile

public static java.io.File createTempFile(java.lang.String prefix,
                                          java.lang.String suffix)
                                   throws java.io.IOException
Throws:
java.io.IOException

createTempFile

public static java.io.File createTempFile(java.lang.String prefix,
                                          java.lang.String suffix,
                                          java.io.File parentDir)
                                   throws java.io.IOException
Throws:
java.io.IOException

stripLeadingSeparator

public static java.lang.String stripLeadingSeparator(java.lang.String name)
Strip any leading separators


hasLeadingSeparator

public static boolean hasLeadingSeparator(java.lang.String name)
Does the name start with a leading separator


stripFirstLeadingSeparator

public static java.lang.String stripFirstLeadingSeparator(java.lang.String name)
Strip first leading separator


stripTrailingSeparator

public static java.lang.String stripTrailingSeparator(java.lang.String name)
Strip any trailing separators


stripPath

public static java.lang.String stripPath(java.lang.String name)
Strips any leading paths


stripExt

public static java.lang.String stripExt(java.lang.String name)

onlyPath

public static java.lang.String onlyPath(java.lang.String name)
Returns only the leading path (returns null if no path)


compactPath

public static java.lang.String compactPath(java.lang.String path)
Compacts a path by stacking it and reducing ..


renameFile

public static boolean renameFile(java.io.File from,
                                 java.io.File to)
Renames a file.

Parameters:
from - the from file
to - the to file
Returns:
true if the file was renamed, otherwise false
Throws:
java.io.IOException - is thrown if error renaming file

renameFile

public static boolean renameFile(java.io.File from,
                                 java.io.File to,
                                 boolean copyAndDeleteOnRenameFail)
                          throws java.io.IOException
Renames a file.

Parameters:
from - the from file
to - the to file
copyAndDeleteOnRenameFail - whether to fallback and do copy and delete, if renameTo fails
Returns:
true if the file was renamed, otherwise false
Throws:
java.io.IOException - is thrown if error renaming file

copyFile

public static void copyFile(java.io.File from,
                            java.io.File to)
                     throws java.io.IOException
Throws:
java.io.IOException

deleteFile

public static boolean deleteFile(java.io.File file)

isAbsolute

public static boolean isAbsolute(java.io.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.


Apache CAMEL