Class FileManager


  • public class FileManager
    extends Object
    Utility class for use by applications containing methods for managing file system files. This class handles application notifications for interesting events.
    • Constructor Detail

      • FileManager

        public FileManager()
        Creates a new file manager.
      • FileManager

        public FileManager​(Application app)
        Creates a new file manager.
        Parameters:
        app - Application managing files to which progress notifications will be sent
    • Method Detail

      • synchronize

        public void synchronize​(File source,
                                File target)
                         throws ApplicationException
        Recursively copies any files or directories appearing in source or a subdirectory of source to the corresponding directory under target. Files in under source are not copied to target if a file by the same name already exists in target.
        Parameters:
        source - source directory
        target - target directory
        Throws:
        ApplicationException - if there is a problem copying files
      • rename

        public void rename​(File fileToRename,
                           File target)
                    throws ApplicationException
        Renames the source file to the target file. If the target file exists it is first deleted. The rename and delete operation return values are checked for success and if unsuccessful, this method throws an exception.
        Parameters:
        fileToRename - The file to rename.
        target - The file to which fileToRename will be moved.
        Throws:
        ApplicationException - If a problem occurs while attempting to rename the file. On the Windows platform, this typically indicates that the file is in use by this or another application.
      • move

        public void move​(File object,
                         File newParent)
                  throws ApplicationException
        Move a file.
        Parameters:
        object - File to move
        newParent - File representing new parent directory
        Throws:
        ApplicationException - if something goes wrong
      • move

        public void move​(File object,
                         File newParent,
                         FileFilter filter)
                  throws ApplicationException
        Move a file.
        Parameters:
        object - File to move
        newParent - File representing new parent directory
        filter - that will be asked whether the operation should be performed
        Throws:
        ApplicationException - if something goes wrong
      • delete

        public void delete​(File object,
                           FileFilter filter)
                    throws ApplicationException
        Deletes a single file or directory.
        Parameters:
        object - File to delete
        filter - that will be asked whether the operation should be performed
        Throws:
        ApplicationException - if something goes wrong
      • deleteChildren

        public void deleteChildren​(File parentDir)
                            throws ApplicationException
        Deletes the children of a directory.
        Parameters:
        parentDir - the directory whose children is deleted
        Throws:
        ApplicationException - if there is a problem deleting children
      • deleteRecursively

        public void deleteRecursively​(File file)
                               throws ApplicationException
        Deletes everything below the specified file.
        Parameters:
        file - the path to be deleted.
        Throws:
        ApplicationException - if something goes wrong.
      • deleteRecursively

        public void deleteRecursively​(File file,
                                      FileFilter filter,
                                      FileManager.DeletionPolicy deletePolicy)
                               throws ApplicationException
        Deletes everything below the specified file.
        Parameters:
        file - the path to be deleted.
        filter - the filter of the files to know if the file can be deleted directly or not.
        deletePolicy - describes how deletions are to be made JVM exits rather than deleting the files immediately.
        Throws:
        ApplicationException - if something goes wrong.
      • copy

        public File copy​(File objectFile,
                         File destDir)
                  throws ApplicationException
        Copies everything below the specified file.
        Parameters:
        objectFile - the file to be copied.
        destDir - the directory to copy the file to
        Returns:
        File representing the destination
        Throws:
        ApplicationException - if something goes wrong.
      • copy

        public File copy​(File objectFile,
                         File destDir,
                         boolean overwrite)
                  throws ApplicationException
        Copies everything below the specified file.
        Parameters:
        objectFile - the file to be copied.
        destDir - the directory to copy the file to
        overwrite - overwrite destination files.
        Returns:
        File representing the destination
        Throws:
        ApplicationException - if something goes wrong.
      • copyRecursively

        public void copyRecursively​(File objectFile,
                                    File destDir)
                             throws ApplicationException
        Copies everything below the specified file.
        Parameters:
        objectFile - the file to be copied.
        destDir - the directory to copy the file to
        Throws:
        ApplicationException - if something goes wrong.
      • copyRecursively

        public void copyRecursively​(File objectFile,
                                    File destDir,
                                    FileFilter filter)
                             throws ApplicationException
        Copies everything below the specified file.
        Parameters:
        objectFile - the file to be copied.
        destDir - the directory to copy the file to
        filter - the filter of the files to know if the file can be copied directly or not.
        Throws:
        ApplicationException - if something goes wrong.
      • copyRecursively

        public void copyRecursively​(File objectFile,
                                    File destDir,
                                    FileFilter filter,
                                    boolean overwrite)
                             throws ApplicationException
        Copies everything below the specified file.
        Parameters:
        objectFile - the file to be copied.
        destDir - the directory to copy the file to
        filter - the filter of the files to know if the file can be copied directly or not.
        overwrite - overwrite destination files.
        Throws:
        ApplicationException - if something goes wrong.
      • filesDiffer

        public boolean filesDiffer​(File f1,
                                   File f2)
                            throws IOException
        Determines whether two files differ in content.
        Parameters:
        f1 - file to compare
        f2 - file to compare
        Returns:
        boolean where true indicates that two files differ
        Throws:
        IOException - if there is a problem reading the files' contents