Class FileUtils


  • public class FileUtils
    extends java.lang.Object
    A utility class containing a few useful static methods to do typical IO operations.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void deleteFile​(java.io.File file, boolean recurse)  
      static boolean deleteFile​(java.io.File file, org.slf4j.Logger logger)
      Deletes the given file.
      static boolean deleteFile​(java.io.File file, org.slf4j.Logger logger, int attempts)
      Deletes the given file.
      static void deleteFiles​(java.util.Collection<java.io.File> files, boolean recurse)
      Deletes given files.
      static void deleteFilesInDirectory​(java.io.File directory, java.io.FilenameFilter filter, org.slf4j.Logger logger)
      Deletes all files (not directories..) in the given directory (non recursive) that match the given filename filter.
      static void deleteFilesInDirectory​(java.io.File directory, java.io.FilenameFilter filter, org.slf4j.Logger logger, boolean recurse)
      Deletes all files (not directories) in the given directory (recursive) that match the given filename filter.
      static void deleteFilesInDirectory​(java.io.File directory, java.io.FilenameFilter filter, org.slf4j.Logger logger, boolean recurse, boolean deleteEmptyDirectories)
      Deletes all files (not directories) in the given directory (recursive) that match the given filename filter.
      static void ensureDirectoryExistAndCanRead​(java.io.File dir)  
      static void ensureDirectoryExistAndCanReadAndWrite​(java.io.File dir)  
      static boolean mayBeANarArchive​(java.io.File jarFile)  
      static void sleepQuietly​(long millis)  
      • Methods inherited from class java.lang.Object

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

      • MILLIS_BETWEEN_ATTEMPTS

        public static final long MILLIS_BETWEEN_ATTEMPTS
        See Also:
        Constant Field Values
    • Constructor Detail

      • FileUtils

        public FileUtils()
    • Method Detail

      • ensureDirectoryExistAndCanReadAndWrite

        public static void ensureDirectoryExistAndCanReadAndWrite​(java.io.File dir)
                                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • ensureDirectoryExistAndCanRead

        public static void ensureDirectoryExistAndCanRead​(java.io.File dir)
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • deleteFile

        public static boolean deleteFile​(java.io.File file,
                                         org.slf4j.Logger logger)
        Deletes the given file. If the given file exists but could not be deleted this will be printed as a warning to the given logger
        Parameters:
        file - to delete
        logger - to notify
        Returns:
        true if deleted
      • deleteFile

        public static boolean deleteFile​(java.io.File file,
                                         org.slf4j.Logger logger,
                                         int attempts)
        Deletes the given file. If the given file exists but could not be deleted this will be printed as a warning to the given logger
        Parameters:
        file - to delete
        logger - to notify
        attempts - indicates how many times an attempt to delete should be made
        Returns:
        true if given file no longer exists
      • deleteFilesInDirectory

        public static void deleteFilesInDirectory​(java.io.File directory,
                                                  java.io.FilenameFilter filter,
                                                  org.slf4j.Logger logger)
                                           throws java.io.IOException
        Deletes all files (not directories..) in the given directory (non recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given logger.
        Parameters:
        directory - to delete contents of
        filter - if null then no filter is used
        logger - to notify
        Throws:
        java.io.IOException - if abstract pathname does not denote a directory, or if an I/O error occurs
      • deleteFilesInDirectory

        public static void deleteFilesInDirectory​(java.io.File directory,
                                                  java.io.FilenameFilter filter,
                                                  org.slf4j.Logger logger,
                                                  boolean recurse)
                                           throws java.io.IOException
        Deletes all files (not directories) in the given directory (recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given logger.
        Parameters:
        directory - to delete contents of
        filter - if null then no filter is used
        logger - to notify
        recurse - true if should recurse
        Throws:
        java.io.IOException - if abstract pathname does not denote a directory, or if an I/O error occurs
      • deleteFilesInDirectory

        public static void deleteFilesInDirectory​(java.io.File directory,
                                                  java.io.FilenameFilter filter,
                                                  org.slf4j.Logger logger,
                                                  boolean recurse,
                                                  boolean deleteEmptyDirectories)
                                           throws java.io.IOException
        Deletes all files (not directories) in the given directory (recursive) that match the given filename filter. If any file cannot be deleted then this is printed at warn to the given logger.
        Parameters:
        directory - to delete contents of
        filter - if null then no filter is used
        logger - to notify
        recurse - will look for contents of sub directories.
        deleteEmptyDirectories - default is false; if true will delete directories found that are empty
        Throws:
        java.io.IOException - if abstract pathname does not denote a directory, or if an I/O error occurs
      • deleteFiles

        public static void deleteFiles​(java.util.Collection<java.io.File> files,
                                       boolean recurse)
                                throws java.io.IOException
        Deletes given files.
        Parameters:
        files - to delete
        recurse - will recurse
        Throws:
        java.io.IOException - if issues deleting files
      • deleteFile

        public static void deleteFile​(java.io.File file,
                                      boolean recurse)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • sleepQuietly

        public static void sleepQuietly​(long millis)
      • mayBeANarArchive

        public static boolean mayBeANarArchive​(java.io.File jarFile)