Package org.apache.pulsar.common.nar
Class FileUtils
- java.lang.Object
-
- org.apache.pulsar.common.nar.FileUtils
-
public class FileUtils extends java.lang.ObjectA utility class containing a few useful static methods to do typical IO operations.
-
-
Field Summary
Fields Modifier and Type Field Description static longMILLIS_BETWEEN_ATTEMPTS
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddeleteFile(java.io.File file, boolean recurse)static booleandeleteFile(java.io.File file, org.slf4j.Logger logger)Deletes the given file.static booleandeleteFile(java.io.File file, org.slf4j.Logger logger, int attempts)Deletes the given file.static voiddeleteFiles(java.util.Collection<java.io.File> files, boolean recurse)Deletes given files.static voiddeleteFilesInDirectory(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 voiddeleteFilesInDirectory(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 voiddeleteFilesInDirectory(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 voidensureDirectoryExistAndCanRead(java.io.File dir)static voidensureDirectoryExistAndCanReadAndWrite(java.io.File dir)static booleanmayBeANarArchive(java.io.File jarFile)static voidsleepQuietly(long millis)
-
-
-
Field Detail
-
MILLIS_BETWEEN_ATTEMPTS
public static final long MILLIS_BETWEEN_ATTEMPTS
- See Also:
- Constant Field Values
-
-
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 deletelogger- 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 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(java.io.File directory, java.io.FilenameFilter filter, org.slf4j.Logger logger) throws java.io.IOExceptionDeletes 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:
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.IOExceptionDeletes 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:
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.IOExceptionDeletes 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:
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.IOExceptionDeletes given files.- Parameters:
files- to deleterecurse- 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)
-
-