Class FileUtils

java.lang.Object
org.apache.pulsar.common.nar.FileUtils

public class FileUtils extends Object
A utility class containing a few useful static methods to do typical IO operations.
  • Field Details

    • MILLIS_BETWEEN_ATTEMPTS

      public static final long MILLIS_BETWEEN_ATTEMPTS
      See Also:
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • ensureDirectoryExistAndCanReadAndWrite

      public static void ensureDirectoryExistAndCanReadAndWrite(File dir) throws IOException
      Throws:
      IOException
    • ensureDirectoryExistAndCanRead

      public static void ensureDirectoryExistAndCanRead(File dir) throws IOException
      Throws:
      IOException
    • deleteFile

      public static boolean deleteFile(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(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(File directory, FilenameFilter filter, org.slf4j.Logger logger) throws 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:
      IOException - if abstract pathname does not denote a directory, or if an I/O error occurs
    • deleteFilesInDirectory

      public static void deleteFilesInDirectory(File directory, FilenameFilter filter, org.slf4j.Logger logger, boolean recurse) throws 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:
      IOException - if abstract pathname does not denote a directory, or if an I/O error occurs
    • deleteFilesInDirectory

      public static void deleteFilesInDirectory(File directory, FilenameFilter filter, org.slf4j.Logger logger, boolean recurse, boolean deleteEmptyDirectories) throws 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:
      IOException - if abstract pathname does not denote a directory, or if an I/O error occurs
    • deleteFiles

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

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

      public static void sleepQuietly(long millis)
    • mayBeANarArchive

      public static boolean mayBeANarArchive(File jarFile)