| java.lang.Object org.apache.commons.io.FileDeleteStrategy
FileDeleteStrategy | public class FileDeleteStrategy (Code) | | Strategy for deleting files.
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.
author: Stephen Colebourne version: $Id: FileDeleteStrategy.java 453903 2006-10-07 13:47:06Z scolebourne $ since: Commons IO 1.3 |
Field Summary | |
final public static FileDeleteStrategy | FORCE The singleton instance for forced file deletion, which always deletes,
even if the file represents a non-empty directory. | final public static FileDeleteStrategy | NORMAL The singleton instance for normal file deletion, which does not permit
the deletion of directories that are not empty. |
Method Summary | |
public void | delete(File fileToDelete) Deletes the file object, which may be a file or a directory. | public 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.
This method is designed for subclasses to override.
The implementation may return either false or an IOException
when deletion fails. | public String | toString() Gets a string describing the delete strategy. |
FORCE | final public static FileDeleteStrategy FORCE(Code) | | The singleton instance for forced file deletion, which always deletes,
even if the file represents a non-empty directory.
|
NORMAL | final public static FileDeleteStrategy NORMAL(Code) | | The singleton instance for normal file deletion, which does not permit
the deletion of directories that are not empty.
|
FileDeleteStrategy | protected FileDeleteStrategy(String name)(Code) | | Restricted constructor.
Parameters: name - the name by which the strategy is known |
delete | public void delete(File fileToDelete) throws IOException(Code) | | Deletes the file object, which may be a file or a directory.
If the file does not exist, the method just returns.
Subclass writers should override
FileDeleteStrategy.doDelete(File) , not this method.
Parameters: fileToDelete - the file to delete, not null throws: NullPointerException - if the file is null throws: IOException - if an error occurs during file deletion |
deleteQuietly | public boolean deleteQuietly(File fileToDelete)(Code) | | Deletes the file object, which may be a file or a directory.
All IOException s are caught and false returned instead.
If the file does not exist or is null, true is returned.
Subclass writers should override
FileDeleteStrategy.doDelete(File) , not this method.
Parameters: fileToDelete - the file to delete, null returns true true if the file was deleted, or there was no such file |
doDelete | protected boolean doDelete(File fileToDelete) throws IOException(Code) | | Actually deletes the file object, which may be a file or a directory.
This method is designed for subclasses to override.
The implementation may return either false or an IOException
when deletion fails. The
FileDeleteStrategy.delete(File) and
FileDeleteStrategy.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 .
Parameters: fileToDelete - the file to delete, exists, not null true if the file was deleteds throws: NullPointerException - if the file is null throws: IOException - if an error occurs during file deletion |
toString | public String toString()(Code) | | Gets a string describing the delete strategy.
a string describing the delete strategy |
|
|