Package org.apache.pulsar.common.nar
Class FileUtils
java.lang.Object
org.apache.pulsar.common.nar.FileUtils
A utility class containing a few useful static methods to do typical IO
operations.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
deleteFile
(File file, boolean recurse) static boolean
deleteFile
(File file, org.slf4j.Logger logger) Deletes the given file.static boolean
deleteFile
(File file, org.slf4j.Logger logger, int attempts) Deletes the given file.static void
deleteFiles
(Collection<File> files, boolean recurse) Deletes given files.static void
deleteFilesInDirectory
(File directory, 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
(File directory, 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
(File directory, 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
static void
static boolean
mayBeANarArchive
(File jarFile) static void
sleepQuietly
(long millis)
-
Field Details
-
MILLIS_BETWEEN_ATTEMPTS
public static final long MILLIS_BETWEEN_ATTEMPTS- See Also:
-
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
ensureDirectoryExistAndCanReadAndWrite
- Throws:
IOException
-
ensureDirectoryExistAndCanRead
- Throws:
IOException
-
deleteFile
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 deletelogger
- to notify- Returns:
- true if deleted
-
deleteFile
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 deletelogger
- to notifyattempts
- 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 offilter
- if null then no filter is usedlogger
- 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 offilter
- if null then no filter is usedlogger
- to notifyrecurse
- 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 offilter
- if null then no filter is usedlogger
- to notifyrecurse
- 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
Deletes given files.- Parameters:
files
- to deleterecurse
- will recurse- Throws:
IOException
- if issues deleting files
-
deleteFile
- Throws:
IOException
-
sleepQuietly
public static void sleepQuietly(long millis) -
mayBeANarArchive
-