Example usage for org.apache.commons.io FileUtils forceDelete

List of usage examples for org.apache.commons.io FileUtils forceDelete

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils forceDelete.

Prototype

public static void forceDelete(File file) throws IOException 

Source Link

Document

Deletes a file.

Usage

From source file:com.atlauncher.Bootstrap.java

public static void main(String[] args) {
    String json = null;//from   ww w. j av a 2 s.  com

    if (!Files.isDirectory(PATH)) {
        try {
            Files.createDirectories(PATH);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    try {
        json = IOUtils.toString(URI.create("http://download.nodecdn.net/containers/atl/v4/app.json"));
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
    }

    Application application = GSON.fromJson(json, Application.class);

    Dependency currentDependency = null;

    if (Files.exists(PATH.resolve("nwjs.json"))) {
        try {
            currentDependency = GSON.fromJson(FileUtils.readFileToString(PATH.resolve("nwjs.json").toFile()),
                    Dependency.class);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    for (Dependency dependency : application.getDependencies()) {
        if (dependency.shouldInstall() && !dependency.matches(currentDependency)) {
            if (Files.isDirectory(PATH.resolve("nwjs/"))) {
                try {
                    FileUtils.deleteDirectory(PATH.resolve("nwjs/").toFile());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            try {
                File zipFile = PATH.resolve("nwjs/temp.zip").toFile();
                FileUtils.copyURLToFile(dependency.getUrl(), zipFile);
                Utils.unzip(zipFile, PATH.resolve("nwjs/").toFile());
                FileUtils.forceDelete(zipFile);

                currentDependency = dependency;

                FileUtils.writeStringToFile(PATH.resolve("nwjs.json").toFile(), GSON.toJson(dependency));

                break;
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }

    App currentApp = null;

    if (Files.exists(PATH.resolve("app.json"))) {
        try {
            currentApp = GSON.fromJson(FileUtils.readFileToString(PATH.resolve("app.json").toFile()),
                    App.class);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    if (!application.getApp().matches(currentApp)
            || (currentApp != null && !Files.exists(PATH.resolve(currentApp.getFilename())))) {
        if (currentApp != null && Files.exists(PATH.resolve(currentApp.getFilename()))) {
            try {
                FileUtils.forceDelete(PATH.resolve(currentApp.getFilename()).toFile());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        try {
            FileUtils.copyURLToFile(application.getApp().getUrl(),
                    PATH.resolve(application.getApp().getFilename()).toFile());

            currentApp = application.getApp();

            FileUtils.writeStringToFile(PATH.resolve("app.json").toFile(), GSON.toJson(application.getApp()));
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    if (currentDependency == null || currentApp == null) {
        System.exit(1);
    }

    List<String> arguments = new ArrayList<>();
    arguments.add(PATH.resolve("nwjs/").toAbsolutePath() + currentDependency.getStartup());
    arguments.add(currentApp.getFilename());
    ProcessBuilder processBuilder = new ProcessBuilder(arguments);
    processBuilder.directory(PATH.toFile());
    try {
        processBuilder.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.sustainalytics.crawlerfilter.PDFtoTextBatch.java

/**
 * Driver method for the class/*from ww w .j a  v  a 2 s  .c om*/
 * @param args contains the file path and name
 */
public static void main(String[] args) {
    showBanner();
    File folder = new File(args[0]);
    //      initiateLogger(folder);
    File[] listOfFiles = folder.listFiles();
    int parserChoice = Integer.parseInt(args[1]);

    String content = null;
    for (int i = 0; i < listOfFiles.length; i++) {
        if (parserChoice == 1) {
            content = extractPDFText(listOfFiles[i].getAbsoluteFile());
        } else if (parserChoice == 2) {
            content = extractFoxitText(listOfFiles[i].getAbsolutePath());
        } else if (parserChoice == 3) {
            content = extractPDFExtremeText(listOfFiles[i].getAbsolutePath());
        } else if (parserChoice == 4) {
            content = extractITextText(listOfFiles[i].getAbsolutePath());
        } else if (parserChoice == 5) {
            content = extractTikaText(listOfFiles[i].getAbsolutePath());
        }
        writeParsedFile(listOfFiles[i].getAbsolutePath(), content);
        try {
            FileUtils.forceDelete(listOfFiles[i].getAbsoluteFile());
        } catch (IOException e) {
            System.out.println("Failed to delete file");
        }
    }
}

From source file:launcher.License.java

public static void deleteCache() {
    try {// ww w  .  ja  va2s. c om
        FileUtils.forceDelete(Cache);
    } catch (IOException e) {
        LaunchLogger.error("There was a problem deleting the license cache.");
        LaunchLogger.exception(e);
    }
}

From source file:com.hp.autonomy.idolutils.GenerateIndexableXmlDocumentTest.java

@AfterClass
public static void destroy() throws IOException {
    FileUtils.forceDelete(TEST_DIR);
}

From source file:com.liferay.maven.plugins.util.FileUtil.java

public static void delete(File file) throws IOException {
    FileUtils.forceDelete(file);
}

From source file:com.tw.go.plugin.material.artifactrepository.yum.exec.RepoqueryCacheCleaner.java

public static void performCleanup() throws IOException {
    File[] cacheFiles = new File("/var/tmp/").listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            String currentUser = System.getProperty("user.name") != null ? System.getProperty("user.name")
                    : "go";
            return name.startsWith(String.format("yum-%s-", currentUser));
        }//from  w  w  w.ja v  a  2s. c  om
    });
    for (File cacheFile : cacheFiles) {
        FileUtils.forceDelete(cacheFile);
    }
}

From source file:com.baifendian.swordfish.execserver.utils.EnvHelper.java

/**
 * /*from  w w  w.ja  v  a  2 s. co m*/
 *
 * @param execLocalPath
 * @param proxyUser
 * @param logger
 * @throws IOException
 */
public static void workDirAndUserCreate(String execLocalPath, String proxyUser, Logger logger)
        throws IOException {
    // , 
    File execLocalPathFile = new File(execLocalPath);

    if (execLocalPathFile.exists()) {
        FileUtils.forceDelete(execLocalPathFile);
    }

    // 
    FileUtils.forceMkdir(execLocalPathFile);

    // proxyUser ?, ?
    List<String> osUserList = OsUtil.getUserList();

    // ?, 
    if (!osUserList.contains(proxyUser)) {
        String userGroup = OsUtil.getGroup();
        if (StringUtils.isNotEmpty(userGroup)) {
            logger.info("create os user:{}", proxyUser);

            String cmd = String.format("sudo useradd -g %s %s", userGroup, proxyUser);

            logger.info("exec cmd: {}", cmd);

            OsUtil.exeCmd(cmd);
        }
    }
}

From source file:com.stratio.crossdata.connector.plugin.installer.InstallerGoalLauncher.java

public static void launchInstallerGoal(InstallerGoalConfig config, Log log) throws IOException {

    log.info("Create TARGET directory.");
    File targetDirectory = new File(
            FilenameUtils.concat(config.getOutputDirectory(), config.getConnectorName()));
    if (targetDirectory.exists()) {
        log.info("Remove previous TARGET directory");
        FileUtils.forceDelete(targetDirectory);
    }/*from ww w . j  a  va2s .c om*/
    File includeConfigDirectory = new File(config.getIncludeDirectory());
    FileUtils.copyDirectory(includeConfigDirectory, targetDirectory);

    log.info("Create LIB directory.");
    File libDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "lib"));
    FileUtils.copyFileToDirectory(config.getMainJarRepo(), libDirectory);
    for (File jarFile : config.getDependenciesJarRepo()) {
        FileUtils.copyFileToDirectory(jarFile, libDirectory);
    }

    log.info("Create CONF directory.");
    File confDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "conf"));
    File confConfigDirectory = new File(config.getConfigDirectory());
    FileUtils.copyDirectory(confConfigDirectory, confDirectory);

    log.info("Create BIN Directory");
    File binDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "bin"));
    FileUtils.forceMkdir(binDirectory);

    log.info("Launch template");
    String outputString = (config.getUnixScriptTemplate());
    outputString = outputString.replaceAll("<name>", config.getConnectorName());
    outputString = outputString.replaceAll("<desc>", config.getDescription());
    String user = config.getUserService();
    if (config.isUseCallingUserAsService()) {
        user = System.getProperty("user.name");
    }
    outputString = outputString.replaceAll("<user>", user);
    outputString = outputString.replaceAll("<mainClass>", config.getMainClass());
    int index = config.getMainClass().lastIndexOf('.');
    String className = config.getMainClass();
    if (index != -1) {
        className = config.getMainClass().substring(index + 1);
    }
    outputString = outputString.replaceAll("<mainClassName>", className);

    outputString = outputString.replaceAll("<jmxPort>", config.getJmxPort());
    String pidFileName = "";
    if (config.getPidFileName() != null) {
        pidFileName = config.getPidFileName();
    }
    outputString = outputString.replaceAll("<pidFileName>", pidFileName);

    File binFile = new File(FilenameUtils.concat(binDirectory.toString(), config.getConnectorName()));
    FileUtils.writeStringToFile(binFile, outputString);
    if (!binFile.setExecutable(true)) {
        throw new IOException("Can't change executable option.");
    }

    log.info("Process complete: " + targetDirectory);
}

From source file:com.hp.autonomy.frontend.find.core.test.AbstractFindIT.java

@AfterClass
public static void destroy() throws IOException {
    FileUtils.forceDelete(new File(TEST_DIR));
}

From source file:net.orfjackal.dimdwarf.testutils.Sandbox.java

private static void retryingForceDelete(File dir) throws IOException {
    long limit = System.currentTimeMillis() + 1000;
    IOException unableToDelete;//from  w  w w .j ava2s . c om
    do {
        try {
            FileUtils.forceDelete(dir);
            return;
        } catch (IOException e) {
            System.err.println("WARNING: " + e.getMessage() + " Retrying...");
            unableToDelete = e;
        }
        sleep(10);
    } while (System.currentTimeMillis() < limit);
    throw unableToDelete;
}