org.apache.commons.io

Class FileDeleteStrategy

Known Direct Subclasses:
FileDeleteStrategy.ForceFileDeleteStrategy

public class FileDeleteStrategy
extends java.lang.Object

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.

Version:
$Id: FileDeleteStrategy.java 453903 2006-10-07 13:47:06Z scolebourne $
Author:
Stephen Colebourne
Since:
Commons IO 1.3

Nested Class Summary

(package private) static class
FileDeleteStrategy.ForceFileDeleteStrategy
Force file deletion strategy.

Field Summary

static FileDeleteStrategy
FORCE
The singleton instance for forced file deletion, which always deletes, even if the file represents a non-empty directory.
static FileDeleteStrategy
NORMAL
The singleton instance for normal file deletion, which does not permit the deletion of directories that are not empty.
private String
name
The name of the strategy.

Constructor Summary

FileDeleteStrategy(String name)
Restricted constructor.

Method Summary

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.

Field Details

FORCE

public static final FileDeleteStrategy FORCE
The singleton instance for forced file deletion, which always deletes, even if the file represents a non-empty directory.

NORMAL

public static final FileDeleteStrategy NORMAL
The singleton instance for normal file deletion, which does not permit the deletion of directories that are not empty.

name

private final String name
The name of the strategy.

Constructor Details

FileDeleteStrategy

protected FileDeleteStrategy(String name)
Restricted constructor.
Parameters:
name - the name by which the strategy is known

Method Details

delete

public void delete(File fileToDelete)
            throws IOException
Parameters:
fileToDelete - the file to delete, not null

deleteQuietly

public boolean deleteQuietly(File fileToDelete)
Parameters:
fileToDelete - the file to delete, null returns true
Returns:
true if the file was deleted, or there was no such file

doDelete

protected boolean doDelete(File fileToDelete)
            throws IOException
Parameters:
fileToDelete - the file to delete, exists, not null
Returns:
true if the file was deleteds

toString

public String toString()
Gets a string describing the delete strategy.
Returns:
a string describing the delete strategy

Copyright (c) 2002-2008 Apache Software Foundation