Example usage for org.springframework.core.io FileSystemResource getDescription

List of usage examples for org.springframework.core.io FileSystemResource getDescription

Introduction

In this page you can find the example usage for org.springframework.core.io FileSystemResource getDescription.

Prototype

@Override
public String getDescription() 

Source Link

Document

This implementation returns a description that includes the absolute path of the file.

Usage

From source file:org.emonocot.harvest.common.MultiResourceDeletingTasklet.java

/**
 * @param contribution Set the step contribution
 * @param chunkContext Set the chunk context
 * @return the repeat status/*from   w  w w.  ja v a2  s .c  o m*/
 * @throws Exception if there is a problem deleting the resources
 */
public final RepeatStatus execute(final StepContribution contribution, final ChunkContext chunkContext)
        throws Exception {
    for (Resource lResource : resources) {
        FileSystemResource lFileSystemResource = new FileSystemResource(lResource.getFile().getAbsolutePath());
        if (!lFileSystemResource.exists()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Resource " + lFileSystemResource.getDescription()
                        + " does not exist. The resource is ignored");
            }
        } else {
            File lFile = lFileSystemResource.getFile();
            if (lFile.isDirectory()) {
                // supprime le rpertoire et son contenu
                FileUtils.deleteDirectory(lFile);
            } else {
                if (!lFile.delete()) {
                    throw new IOException("The file " + lFile + " cannot be deleted.");
                }
            }
        }
    }
    return RepeatStatus.FINISHED;
}