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

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

Introduction

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

Prototype

public static void deleteDirectory(File directory) throws IOException 

Source Link

Document

Deletes a directory recursively.

Usage

From source file:com.datatorrent.contrib.hdht.HDHTReaderTest.java

@Test
public void testReader() throws Exception {
    File file = new File(testInfo.getDir());
    FileUtils.deleteDirectory(file);

    FileAccessFSImpl fa = new MockFileAccess();
    fa.setBasePath(file.getAbsolutePath());

    Slice key0 = HDHTWriterTest.newKey(1, 0);
    String data0 = "data0";

    Slice key1 = HDHTWriterTest.newKey(1, 1);
    String data1 = "data1";

    writeKey(fa, key0, data0);//from  w  w  w  .j  a  v  a 2 s. c om
    writeKey(fa, key1, data1);

    // setup the reader instance
    final List<HDSQuery> results = Lists.newArrayList();
    HDHTReader reader = new HDHTReader() {
        @Override
        protected void emitQueryResult(HDSQuery query) {
            results.add(query);
        }
    };
    reader.queryExecutor = MoreExecutors.sameThreadExecutor(); // synchronous endWindow processing
    reader.setFileStore(fa);

    reader.setup(null);
    reader.beginWindow(1);

    HDSQuery q = new HDSQuery();
    q.bucketKey = HDHTWriterTest.getBucketKey(key1);
    q.keepAliveCount = 1;
    q.key = key1;

    reader.addQuery(q);
    Assert.assertNull("query result before endWindow", q.result);
    Assert.assertEquals("query results", 0, results.size());

    reader.endWindow(); // process query

    Assert.assertArrayEquals("query result after endWindow", data1.getBytes(), q.result);
    Assert.assertEquals("query results", 1, results.size());

    reader.beginWindow(2);
    reader.endWindow(); // emit result again

    Assert.assertEquals("query results", 2, results.size());

    reader.beginWindow(3);
    reader.endWindow(); // emit nothing - query expired

    Assert.assertEquals("query expired", 2, results.size());

    // unknown key
    results.clear();

    Slice key2 = HDHTWriterTest.newKey(1, 2);
    HDSQuery q2 = new HDSQuery();
    q2.bucketKey = HDHTWriterTest.getBucketKey(key2);
    q2.keepAliveCount = 1;
    q2.key = key2;

    reader.beginWindow(4);
    reader.addQuery(q2);
    reader.endWindow(); // emit nothing - unknown key
    Assert.assertEquals("query results " + results, 1, results.size());
    Assert.assertEquals("query result " + results.get(0), key2, results.get(0).key);
    Assert.assertEquals("query result " + results.get(0), null, results.get(0).result);

    reader.teardown();
}

From source file:dmh.kuebiko.model.filesystem.FileSystemNoteDaoTest.java

@AfterClass
public void classCleanup() throws IOException {
    FileUtils.deleteDirectory(tempDir);

    tempDir = null;
    params = null;
}

From source file:net.mybox.mybox.ServerAdmin.java

/**
 * Delete account and update user database
 *//* w  w w.j a v  a 2  s .  c om*/
private void deleteAccount() {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    accountsDb.showAccounts();

    Server.printMessage_("Which account would you like to delete?\naccount number> ");

    String input = null;
    try {
        input = br.readLine();
    } catch (Exception e) {
    }

    AccountsDB.Account thisAccount = accountsDb.getAccountByID(input);

    if (thisAccount == null) {
        System.out.println("account " + input + " does not exist.");
        return;
    }

    System.out.println("Are you sure you want to delete " + thisAccount);
    System.out.print("y/n> ");

    try {
        input = br.readLine();
    } catch (Exception e) {
    }

    if (input.equals("y")) {

        // delete the data directory
        File userDir = new File(Server.GetAbsoluteDataDirectory(thisAccount));

        try {
            FileUtils.deleteDirectory(userDir);
        } catch (IOException ex) {
            Server.printWarning("There was a problem deleting the user directory " + ex.getMessage());
        }

        // update the database
        if (accountsDb.deleteAccount(thisAccount.id))
            System.out.println("Account deleted");
        else
            System.out.println("Unable to delete account from database");
    }

}

From source file:de.akquinet.innovation.play.maven.Play2CleanMojo.java

public void execute() throws MojoExecutionException {

    String line = getPlay2().getAbsolutePath();

    CommandLine cmdLine = CommandLine.parse(line);
    cmdLine.addArgument("clean");
    DefaultExecutor executor = new DefaultExecutor();

    if (timeout > 0) {
        ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
        executor.setWatchdog(watchdog);/*from  w  w  w  . j  a va2s  . co m*/
    }

    executor.setWorkingDirectory(project.getBasedir());
    executor.setExitValue(0);
    try {
        executor.execute(cmdLine, getEnvironment());
    } catch (IOException e) {
        throw new MojoExecutionException("Error during cleanup", e);
    }

    // Also delete the dist directory
    File dist = new File(project.getBasedir(), "dist");
    if (dist.exists()) {
        getLog().debug("Deleting " + dist.getAbsolutePath());
        try {
            FileUtils.deleteDirectory(dist);
        } catch (IOException e) {
            throw new MojoExecutionException("Can't delete the dist folder", e);
        }
    } else {
        getLog().debug("'dist' directory not found");
    }

    // Delete the log folder
    File logs = new File(project.getBasedir(), "logs");
    if (logs.exists()) {
        getLog().debug("Deleting " + logs.getAbsolutePath());
        try {
            FileUtils.deleteDirectory(logs);
        } catch (IOException e) {
            throw new MojoExecutionException("Can't delete the logs folder", e);
        }
    } else {
        getLog().debug("'logs' directory not found");
    }

    // Also delete the lib directory if set
    if (cleanLibFolder) {
        File lib = new File(project.getBasedir(), "lib");
        if (lib.exists()) {
            getLog().debug("Deleting " + lib.getAbsolutePath());
            try {
                FileUtils.deleteDirectory(lib);
            } catch (IOException e) {
                throw new MojoExecutionException("Can't delete the " + lib + " folder", e);
            }
        } else {
            getLog().debug("'" + lib + "' directory not found");
        }
    }
}

From source file:com.badlogicgames.packr.PackrReduce.java

static void minimizeJre(PackrOutput output, PackrConfig config) throws IOException {
    if (config.minimizeJre == null) {
        return;//  w  w w  . j ava  2 s  . co m
    }

    System.out.println("Minimizing JRE ...");

    JsonObject minimizeJson = readMinimizeProfile(config);
    if (minimizeJson != null) {
        if (config.verbose) {
            System.out
                    .println("  # Removing files and directories in profile '" + config.minimizeJre + "' ...");
        }

        JsonArray reduceArray = minimizeJson.get("reduce").asArray();
        for (JsonValue reduce : reduceArray) {
            String path = reduce.asObject().get("archive").asString();
            File file = new File(output.resourcesFolder, path);

            if (!file.exists()) {
                if (config.verbose) {
                    System.out.println("  # No file or directory '" + file.getPath() + "' found, skipping");
                }
                continue;
            }

            boolean needsUnpack = !file.isDirectory();

            File fileNoExt = needsUnpack
                    ? new File(output.resourcesFolder,
                            path.contains(".") ? path.substring(0, path.lastIndexOf('.')) : path)
                    : file;

            if (needsUnpack) {
                if (config.verbose) {
                    System.out.println("  # Unpacking '" + file.getPath() + "' ...");
                }
                ZipUtil.unpack(file, fileNoExt);
            }

            JsonArray removeArray = reduce.asObject().get("paths").asArray();
            for (JsonValue remove : removeArray) {
                File removeFile = new File(fileNoExt, remove.asString());
                if (removeFile.exists()) {
                    if (removeFile.isDirectory()) {
                        FileUtils.deleteDirectory(removeFile);
                    } else {
                        PackrFileUtils.delete(removeFile);
                    }
                } else {
                    if (config.verbose) {
                        System.out.println("  # No file or directory '" + removeFile.getPath() + "' found");
                    }
                }
            }

            if (needsUnpack) {
                if (config.verbose) {
                    System.out.println("  # Repacking '" + file.getPath() + "' ...");
                }

                long beforeLen = file.length();
                PackrFileUtils.delete(file);

                ZipUtil.pack(fileNoExt, file);
                FileUtils.deleteDirectory(fileNoExt);

                long afterLen = file.length();

                if (config.verbose) {
                    System.out.println("  # " + beforeLen / 1024 + " kb -> " + afterLen / 1024 + " kb");
                }
            }
        }

        JsonArray removeArray = minimizeJson.get("remove").asArray();
        for (JsonValue remove : removeArray) {
            String platform = remove.asObject().get("platform").asString();

            if (!matchPlatformString(platform, config)) {
                continue;
            }

            JsonArray removeFilesArray = remove.asObject().get("paths").asArray();
            for (JsonValue removeFile : removeFilesArray) {
                removeFileWildcard(output.resourcesFolder, removeFile.asString(), config);
            }
        }
    }
}

From source file:com.zyz.mobile.file.FileClipboard.java

/**
 * Delete the specified file./*from w  w  w  . j  a  v a  2 s  . co m*/
 *
 * @param file the file to be deleted
 */
public static void deleteFile(File file) throws IOException {
    if (file.isFile()) {
        file.delete();
    } else {
        FileUtils.deleteDirectory(file);
    }
}

From source file:io.druid.indexing.common.tasklogs.FileTaskLogsTest.java

@Test
public void testSimple() throws Exception {
    final File tmpDir = temporaryFolder.newFolder();
    try {/* ww w .j  a va2  s  .  c o m*/
        final File logDir = new File(tmpDir, "druid/logs");
        final File logFile = new File(tmpDir, "log");
        Files.write("blah", logFile, Charsets.UTF_8);
        final TaskLogs taskLogs = new FileTaskLogs(new FileTaskLogsConfig(logDir));
        taskLogs.pushTaskLog("foo", logFile);

        final Map<Long, String> expected = ImmutableMap.of(0L, "blah", 1L, "lah", -2L, "ah", -5L, "blah");
        for (Map.Entry<Long, String> entry : expected.entrySet()) {
            final byte[] bytes = ByteStreams
                    .toByteArray(taskLogs.streamTaskLog("foo", entry.getKey()).get().getInput());
            final String string = new String(bytes);
            Assert.assertEquals(String.format("Read with offset %,d", entry.getKey()), string,
                    entry.getValue());
        }
    } finally {
        FileUtils.deleteDirectory(tmpDir);
    }
}

From source file:mesclasses.util.EleveFileUtil.java

public static void purge() throws IOException {
    File dir = new File(FileConfigurationManager.getInstance().getUploadDir());
    FileUtils.deleteDirectory(dir);
    new File(FileConfigurationManager.getInstance().getUploadDir()).mkdirs();
}

From source file:de.mendelson.comm.as2.AS2.java

public static void cleanup() {
    // RJC:  Runtime creates database, lock, and log artifacts.  During 
    // development time this is very annoying.  Temporarily cleaning
    // up these artifacts...
    // TODO better solution at some point (need persistent state)
    String RUNTIME_ARTIFACTS[] = new String[] { "AS2_DB_CONFIG.log", "AS2_DB_CONFIG.script",
            "AS2_DB_RUNTIME.log", "AS2_DB_RUNTIME.script", "client_server_session0.logd",
            "client_server_session1.logd", "client_server_session2.logd", "AS2_DB_CONFIG.properties",
            "AS2_DB_CONFIG.tmp", "AS2_DB_RUNTIME.properties", "AS2_DB_RUNTIME.tmp",
            "client_server_session0.log.lck", "client_server_session1.log.lck",
            "client_server_session2.log.lck", "mendelson_opensource_AS2.lock", "messages",
            "AS2_DB_CONFIG.properties", "AS2_DB_CONFIG.script", "AS2_DB_RUNTIME.properties",
            "AS2_DB_RUNTIME.script", "client_server_session0.log.lck", "client_server_session0.log" };

    for (String s : RUNTIME_ARTIFACTS) {
        File f = new File(s);
        if (f.isFile()) {
            f.delete();//from  w ww. j  av  a2  s .c  om
        } else {
            if (f.isDirectory()) {
                try {
                    FileUtils.deleteDirectory(f);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }
    }

}

From source file:io.wcm.devops.conga.plugins.sling.postprocessor.ProvisioningOsgiConfigPostProcessorTest.java

@After
public void tearDown() throws IOException {
    FileUtils.deleteDirectory(targetDir);
}