org.apache.commons.io.FileDeleteStrategy Java Examples

The following examples show how to use org.apache.commons.io.FileDeleteStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileLocationValidator.java    From jresume with MIT License 6 votes vote down vote up
@Override
public void validate(String name, String value) throws ParameterException {
    File file = new File(value);
    ParameterException exception = new ParameterException("File " + file.getAbsolutePath() + " does not exist and cannot be created.");
    try {

        if (!file.exists()) {
            boolean canCreate = file.createNewFile();
            if (canCreate) {
                FileDeleteStrategy.FORCE.delete(file);
            } else {
                throw exception;
            }

        }
    } catch (IOException exc) {
        throw exception;
    }

}
 
Example #2
Source File: FileLocationValidator.java    From jresume with MIT License 6 votes vote down vote up
@Override
public void validate(String name, String value) throws ParameterException {
    File file = new File(value);
    ParameterException exception = new ParameterException("File " + file.getAbsolutePath() + " does not exist and cannot be created.");
    try {

        if (!file.exists()) {
            boolean canCreate = file.createNewFile();
            if (canCreate) {
                FileDeleteStrategy.FORCE.delete(file);
            } else {
                throw exception;
            }

        }
    } catch (IOException exc) {
        throw exception;
    }

}
 
Example #3
Source File: HessianServletGenerator.java    From Thunder with Apache License 2.0 6 votes vote down vote up
private void forceDelete(int times) {
    if (times == 0) {
        return;
    }
    if (file.exists()) {
        try {
            FileDeleteStrategy.FORCE.delete(file);
        } catch (IOException e) {
            e.printStackTrace();
            try {
                TimeUnit.MILLISECONDS.sleep(1500);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
            times--;
            forceDelete(times);
        }
    }
}
 
Example #4
Source File: v340Updater.java    From dependency-track with Apache License 2.0 6 votes vote down vote up
public void executeUpgrade(AlpineQueryManager qm, Connection connection) throws SQLException {
    LOGGER.info("Recreating table PROJECT_PROPERTY");
    DbUtil.dropTable(connection, "PROJECT_PROPERTY"); // Will be dynamically recreated

    LOGGER.info("Deleting search engine indices");
    IndexManager.delete(IndexManager.IndexType.LICENSE);
    IndexManager.delete(IndexManager.IndexType.PROJECT);
    IndexManager.delete(IndexManager.IndexType.COMPONENT);
    IndexManager.delete(IndexManager.IndexType.VULNERABILITY);

    LOGGER.info("Deleting Dependency-Check work directory");
    try {
        final String DC_ROOT_DIR = Config.getInstance().getDataDirectorty().getAbsolutePath() + File.separator + "dependency-check";
        FileDeleteStrategy.FORCE.delete(new File(DC_ROOT_DIR));
    } catch (IOException e) {
        LOGGER.error("An error occurred deleting the Dependency-Check work directory", e);
    }
}
 
Example #5
Source File: Router.java    From jresume with MIT License 5 votes vote down vote up
private void prepareEnvironment() throws IOException {
    if (Files.exists(Paths.get("data"))) {
        FileDeleteStrategy.FORCE.delete(new File("data"));
    }

    Files.createDirectory(Paths.get("data"));
}
 
Example #6
Source File: ResumeGenerator.java    From jresume with MIT License 5 votes vote down vote up
private void extractResourcesFromJarFile() throws Exception {
    String classUrl = Main.class.getResource("Main.class").toString();

    URL url = Main.class.getResource("/resources.zip");
    //System.out.println("JAR Resource Zip URL: " + url.toString());
    InputStream inputStream = url.openStream();


    if (config.serverMode) {
        newResourceZip = config.serverInitialResourceZip;
        newResourceFolder = Paths.get("data", "resources").toFile();
    } else {
        newResourceZip = Paths.get(config.outputDirectory, "webresume-resources.zip").toFile();
        newResourceFolder = Paths.get(config.outputDirectory, config.resourceDirectory).toFile();
    }

    if (!newResourceFolder.exists()) {
        newResourceFolder.mkdirs();
    }

    if (newResourceZip.exists()) {
        FileDeleteStrategy.FORCE.delete(newResourceZip);
    }

    Files.copy(inputStream, newResourceZip.toPath());

    ZipFile zipFile = new ZipFile(newResourceZip);
    zipFile.extractAll(newResourceFolder.getAbsolutePath());
}
 
Example #7
Source File: Router.java    From jresume with MIT License 5 votes vote down vote up
private void prepareEnvironment() throws IOException {
    if (Files.exists(Paths.get("data"))) {
        FileDeleteStrategy.FORCE.delete(new File("data"));
    }

    Files.createDirectory(Paths.get("data"));
}
 
Example #8
Source File: ResumeGenerator.java    From jresume with MIT License 5 votes vote down vote up
private void extractResourcesFromJarFile() throws Exception {
    String classUrl = Main.class.getResource("Main.class").toString();

    URL url = Main.class.getResource("/resources.zip");
    //System.out.println("JAR Resource Zip URL: " + url.toString());
    InputStream inputStream = url.openStream();


    if (config.serverMode) {
        newResourceZip = config.serverInitialResourceZip;
        newResourceFolder = Paths.get("data", "resources").toFile();
    } else {
        newResourceZip = Paths.get(config.outputDirectory, "webresume-resources.zip").toFile();
        newResourceFolder = Paths.get(config.outputDirectory, config.resourceDirectory).toFile();
    }

    if (!newResourceFolder.exists()) {
        newResourceFolder.mkdirs();
    }

    if (newResourceZip.exists()) {
        FileDeleteStrategy.FORCE.delete(newResourceZip);
    }

    Files.copy(inputStream, newResourceZip.toPath());

    ZipFile zipFile = new ZipFile(newResourceZip);
    zipFile.extractAll(newResourceFolder.getAbsolutePath());
}
 
Example #9
Source File: ProfileFactory.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param firefoxProfile 
 */
public void shutdownFirefoxProfile(FirefoxProfile firefoxProfile) {
    try {
        if (deleteProfileData) {
            FileDeleteStrategy.FORCE.delete(new File(netExportPathMap.get(firefoxProfile)));
        }
    } catch (IOException ex) {
        Logger.getLogger(this.getClass()).error(ex);
    }
    netExportPathMap.remove(firefoxProfile);
}
 
Example #10
Source File: JReFrameworkerProject.java    From JReFrameworker with MIT License 5 votes vote down vote up
private void clearProjectBuildDirectory(File buildDirectory) throws IOException {
	for(File file : buildDirectory.listFiles()){
		if(file.isDirectory()){
			File directory = file;
			clearProjectBuildDirectory(directory);
			directory.delete();
		} else {
			FileDeleteStrategy.FORCE.delete(file);
		}
	}
}
 
Example #11
Source File: HttpResourceModelProcessor.java    From msf4j with Apache License 2.0 5 votes vote down vote up
private File createAndTrackTempFile(FormItem item) throws IOException {
    if (tmpPathForRequest == null) {
        if (Files.notExists(tempRepoPath)) {
            Files.createDirectory(tempRepoPath);
        }
        tmpPathForRequest = Files.createTempDirectory(tempRepoPath, "tmp");
    }
    Path path = Paths.get(tmpPathForRequest.toString(), item.getName());
    File file = path.toFile();
    StreamUtil.copy(item.openStream(), new FileOutputStream(file), true);
    fileCleaningTracker.track(file, file);
    fileCleaningTracker.track(tmpPathForRequest.toFile(), file, FileDeleteStrategy.FORCE);
    return file;
}
 
Example #12
Source File: GraphDatabaseBenchmark.java    From graphdb-benchmarks with Apache License 2.0 5 votes vote down vote up
public void cleanup()
{
    try
    {
        FileDeleteStrategy.FORCE.delete(config.getDbStorageDirectory());
    }
    catch (IOException e)
    {
        logger.fatal("Unable to clean up db storage directory: " + e.getMessage());
        System.exit(1);
    }
}
 
Example #13
Source File: IndexManager.java    From dependency-track with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the index directory.
 * @since 3.4.0
 */
public static void delete(final IndexType indexType) {
    final File indexDir = getIndexDirectory(indexType);
    if (indexDir.exists()) {
        LOGGER.info("Deleting " + indexType.name().toLowerCase() + " index");
        try {
            FileDeleteStrategy.FORCE.delete(indexDir);
        } catch (IOException e) {
            LOGGER.error("An error occurred deleting the " + indexType.name().toLowerCase() + " index", e);
        }
    }
}