Class FileUtils


  • public class FileUtils
    extends java.lang.Object
    TODO: Consider wrapping FileUtils
    • Constructor Summary

      Constructors 
      Constructor Description
      FileUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copyDirectory​(java.io.File sourceDir, java.io.File newDir)  
      static void copyFileStreams​(java.io.File fromFile, java.io.File toFile)
      Copy a file from one location to another, and set the modification time to match.
      static boolean deleteDir​(java.io.File dir)
      Delete a directory recursively.
      static void deleteDirOnExit​(java.io.File dir)
      Delete a directory recursively.
      static void fileCopy​(java.io.File src, java.io.File dest, boolean overwrite)
      Copies file src to dest using nio.
      static void fileRename​(java.io.File file, java.lang.String newPath)
      Rename a file
      static void fileRename​(java.io.File file, java.lang.String newPath, java.lang.Class clazz)
      Rename a file.
      static java.io.File getBaseDir​(java.util.List<java.io.File> files)
      Return common base directory of the given files
      static java.lang.String getCommonPrefix​(java.util.List<java.lang.String> files)  
      static void mkParentDirs​(java.io.File file)
      Create parent directory structure of a given file, if it doesn't already exist.
      static java.lang.String relativePath​(java.io.File parent, java.io.File child)
      Return the relative path between a parent directory and some child path
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileUtils

        public FileUtils()
    • Method Detail

      • fileCopy

        public static void fileCopy​(java.io.File src,
                                    java.io.File dest,
                                    boolean overwrite)
                             throws java.io.IOException
        Copies file src to dest using nio.
        Parameters:
        src - source file
        dest - destination file
        overwrite - true to overwrite if it already exists
        Throws:
        java.io.IOException - on io error
      • copyFileStreams

        public static void copyFileStreams​(java.io.File fromFile,
                                           java.io.File toFile)
                                    throws java.io.IOException
        Copy a file from one location to another, and set the modification time to match. (Uses java Streams).
        Parameters:
        fromFile - source file
        toFile - dest file
        Throws:
        java.io.IOException - on io error
      • deleteDir

        public static boolean deleteDir​(java.io.File dir)
        Delete a directory recursively. This method will delete all files and subdirectories.
        Parameters:
        dir - Directory to delete
        Returns:
        If no error occurs, true is returned. false otherwise.
      • deleteDirOnExit

        public static void deleteDirOnExit​(java.io.File dir)
        Delete a directory recursively. This method will delete all files and subdirectories.
        Parameters:
        dir - Directory to delete
      • fileRename

        public static void fileRename​(java.io.File file,
                                      java.lang.String newPath,
                                      java.lang.Class clazz)
        Rename a file. Uses Java's nio library to use a lock.
        Parameters:
        file - File to rename
        newPath - Path for new file name
        clazz - Class associated with lock
        Throws:
        CoreException - A CoreException is raised if any underlying I/O operation fails.
      • fileRename

        public static void fileRename​(java.io.File file,
                                      java.lang.String newPath)
        Rename a file
        Parameters:
        file - File to rename
        newPath - Path for new file name
        Throws:
        CoreException - An CoreException is raised if any underlying I/O operation fails.
      • mkParentDirs

        public static void mkParentDirs​(java.io.File file)
                                 throws java.io.IOException
        Create parent directory structure of a given file, if it doesn't already exist.
        Parameters:
        file - File to create directories for
        Throws:
        java.io.IOException - if an I/O error occurs
      • getBaseDir

        public static java.io.File getBaseDir​(java.util.List<java.io.File> files)
        Return common base directory of the given files
        Parameters:
        files -
        Returns:
        common base directory
      • relativePath

        public static java.lang.String relativePath​(java.io.File parent,
                                                    java.io.File child)
        Return the relative path between a parent directory and some child path
        Parameters:
        parent -
        child -
        Returns:
        the relative path for the child
        Throws:
        java.lang.IllegalArgumentException - if child is not a subpath
      • getCommonPrefix

        public static java.lang.String getCommonPrefix​(java.util.List<java.lang.String> files)
      • copyDirectory

        public static void copyDirectory​(java.io.File sourceDir,
                                         java.io.File newDir)
                                  throws java.io.IOException
        Throws:
        java.io.IOException