public class FileDeleteStrategy extends Object
There is more than one way to delete a file. You may want to limit access to certain directories, to only delete directories if they are empty, or maybe to force deletion.
This class captures the strategy to use and is designed for user subclassing.
| Modifier and Type | Field and Description |
|---|---|
static FileDeleteStrategy |
NORMAL
The singleton instance for normal file deletion, which does not permit the deletion of
directories that are not empty.
|
| Modifier | Constructor and Description |
|---|---|
protected |
FileDeleteStrategy(String name)
Restricted constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
delete(File fileToDelete)
Deletes the file object, which may be a file or a directory.
|
boolean |
deleteQuietly(File fileToDelete)
Deletes the file object, which may be a file or a directory.
|
protected boolean |
doDelete(File fileToDelete)
Actually deletes the file object, which may be a file or a directory.
|
String |
toString()
Gets a string describing the delete strategy.
|
public static final FileDeleteStrategy NORMAL
protected FileDeleteStrategy(String name)
name - the name by which the strategy is knownpublic boolean deleteQuietly(File fileToDelete)
IOExceptions
are caught and false returned instead. If the file does not exist or is null, true is
returned.
Subclass writers should override doDelete(File), not this method.
fileToDelete - the file to delete, null returns truepublic void delete(File fileToDelete) throws IOException
Subclass writers should override doDelete(File), not this method.
fileToDelete - the file to delete, not nullNullPointerException - if the file is nullIOException - if an error occurs during file deletionprotected boolean doDelete(File fileToDelete) throws IOException
This method is designed for subclasses to override. The implementation may return either
false or an IOException when deletion fails. The delete(File) and
deleteQuietly(File) methods will handle either response appropriately. A check has
been made to ensure that the file will exist.
This implementation uses File.delete().
fileToDelete - the file to delete, exists, not nullNullPointerException - if the file is nullIOException - if an error occurs during file deletionCopyright © 2006-2012 Apache Software Foundation. All Rights Reserved.