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:cosmos.example.BuildingPermitsExample.java

public static void main(String[] args) throws Exception {
    BuildingPermitsExample example = new BuildingPermitsExample();
    new JCommander(example, args);

    File inputFile = new File(example.fileName);

    Preconditions.checkArgument(inputFile.exists() && inputFile.isFile() && inputFile.canRead(),
            "Expected " + example.fileName + " to be a readable file");

    String zookeepers;/*  www .j a  v a 2  s . c o m*/
    String instanceName;
    Connector connector;
    MiniAccumuloCluster mac = null;
    File macDir = null;

    // Use the MiniAccumuloCluster is requested
    if (example.useMiniAccumuloCluster) {
        macDir = Files.createTempDir();
        String password = "password";
        MiniAccumuloConfig config = new MiniAccumuloConfig(macDir, password);
        config.setNumTservers(1);

        mac = new MiniAccumuloCluster(config);
        mac.start();

        zookeepers = mac.getZooKeepers();
        instanceName = mac.getInstanceName();

        ZooKeeperInstance instance = new ZooKeeperInstance(instanceName, zookeepers);
        connector = instance.getConnector("root", new PasswordToken(password));
    } else {
        // Otherwise connect to a running instance
        zookeepers = example.zookeepers;
        instanceName = example.instanceName;

        ZooKeeperInstance instance = new ZooKeeperInstance(instanceName, zookeepers);
        connector = instance.getConnector(example.username, new PasswordToken(example.password));
    }

    // Instantiate an instance of Cosmos
    Cosmos cosmos = new CosmosImpl(zookeepers);

    // Create a definition for the data we want to load
    Store id = Store.create(connector, new Authorizations(), AscendingIndexIdentitySet.create());

    // Register the definition with Cosmos so it can track its progress.
    cosmos.register(id);

    // Load all of the data from our inputFile
    LoadBuildingPermits loader = new LoadBuildingPermits(cosmos, id, inputFile);
    loader.run();

    // Finalize the SortableResult which will prevent future writes to the data set
    cosmos.finalize(id);

    // Flush the ingest traces to the backend so we can see the results;
    id.sendTraces();

    // Get back the Set of Columns that we've ingested.
    Set<Column> schema = Sets.newHashSet(cosmos.columns(id));

    log.debug("\nColumns: " + schema);

    Iterator<Column> iter = schema.iterator();
    while (iter.hasNext()) {
        Column c = iter.next();
        // Remove the internal ID field and columns that begin with CONTRACTOR_
        if (c.equals(LoadBuildingPermits.ID) || c.name().startsWith("CONTRACTOR_")) {
            iter.remove();
        }
    }

    Iterable<Index> indices = Iterables.transform(schema, new Function<Column, Index>() {

        @Override
        public Index apply(Column col) {
            return Index.define(col);
        }

    });

    // Ensure that we have locality groups set as we expect
    log.info("Ensure locality groups are set");
    id.optimizeIndices(indices);

    // Compact down the data for this SortableResult    
    log.info("Issuing compaction for relevant data");
    id.consolidate();

    final int numTopValues = 10;

    // Walk through each column in the result set
    for (Column c : schema) {
        Stopwatch sw = new Stopwatch();
        sw.start();

        // Get the number of times we've seen each value in a given column
        CloseableIterable<Entry<RecordValue<?>, Long>> groupingsInColumn = cosmos.groupResults(id, c);

        log.info(c.name() + ":");

        // Iterate over the counts, collecting the top N values in each column
        TreeMap<Long, RecordValue<?>> topValues = Maps.newTreeMap();

        for (Entry<RecordValue<?>, Long> entry : groupingsInColumn) {
            if (topValues.size() == numTopValues) {
                Entry<Long, RecordValue<?>> least = topValues.pollFirstEntry();

                if (least.getKey() < entry.getValue()) {
                    topValues.put(entry.getValue(), entry.getKey());
                } else {
                    topValues.put(least.getKey(), least.getValue());
                }
            } else if (topValues.size() < numTopValues) {
                topValues.put(entry.getValue(), entry.getKey());
            }
        }

        for (Long key : topValues.descendingKeySet()) {
            log.info(topValues.get(key).value() + " occurred " + key + " times");
        }

        sw.stop();

        log.info("Took " + sw.toString() + " to run query.\n");
    }

    log.info("Deleting records");

    // Delete the records we've ingested
    if (!example.useMiniAccumuloCluster) {
        // Because I'm lazy and don't want to wait around to run the BatchDeleter when we're just going
        // to rm -rf the directory in a few secs.
        cosmos.delete(id);
    }

    // And shut down Cosmos
    cosmos.close();

    log.info("Cosmos stopped");

    // If we were using MAC, also stop that
    if (example.useMiniAccumuloCluster && null != mac) {
        mac.stop();
        if (null != macDir) {
            FileUtils.deleteDirectory(macDir);
        }
    }
}

From source file:glass.Plugins.utils.java

public static void cleanWorkDir(String output_folder) {
    new File(output_folder).mkdirs();//create if does not exist
    try {//from   w  ww .  j ava  2  s . c  o  m
        FileUtils.deleteDirectory(new File(output_folder));
    } catch (IOException ex) {
        Logger.getLogger(ServerLogPlugin.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
    }
    new File(output_folder).mkdirs();//create if does not exist
}

From source file:awshamondsidefunctions.DeleteLocalFiles.java

public static void delete() throws IOException {
    FileUtils.deleteDirectory(new File("/mnt/Hamond"));
}

From source file:awshamondsidefunctions.MakeHamondDir.java

public static void make() throws IOException {
    File dir = new File("/mnt/Hamond");
    if (dir.exists()) {
        FileUtils.deleteDirectory(dir);
    }//from   w w w  .  j  a  v  a2s.  c  o  m
    dir.mkdir();
}

From source file:msi.gama.doc.util.PrepareEnv.java

public static void prepareDocumentation(boolean online) throws IOException {
    // - Deletes every generated folders      
    // - Creates every folders when they do not exist

    File genFolder = new File(Constants.GEN_FOLDER);
    File testFolder = new File(Constants.TEST_FOLDER);

    if (genFolder.exists()) {
        FileUtils.deleteDirectory(genFolder);
    }//from w w w .jav  a  2  s.  co  m
    if (testFolder.exists()) {
        FileUtils.deleteDirectory(testFolder);
    }

    genFolder.mkdir();
    new File(Constants.JAVA2XML_FOLDER).mkdirs();
    new File(Constants.XML2WIKI_FOLDER).mkdirs();
    new File(Constants.WIKI2WIKI_FOLDER).mkdirs();
    new File(Constants.HTML2XML_FOLDER).mkdirs();
    new File(Constants.PDF_FOLDER).mkdirs();
    new File(Constants.TEST_FOLDER).mkdirs();
    new File(Constants.TOC_GEN_FOLDER).mkdir();

    copyPythonTemplate();
}

From source file:dao.NewEntryDaoTest.java

@AfterClass
public static void tearDownClass() {
    try {//  w  w w  .j a v  a  2s  .  c o  m
        File testFile = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator);
        FileUtils.deleteDirectory(testFile);
    } catch (IOException ex) {
        Logger.getLogger(NewEntryDaoTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:controller.NewEntryTextControllerTest.java

@AfterClass
public static void tearDownClass() {
    File file = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator);
    try {/*from  ww w  .jav  a 2 s.  c  o  m*/
        FileUtils.deleteDirectory(file);
    } catch (IOException ex) {
        Logger.getLogger(NewEntryTextControllerTest.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:controller.PersonalGoalTextControllerTest.java

@AfterClass
public static void tearDownClass() {

    File file = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator);
    try {//w w w  . j  a  v a 2s .c om
        FileUtils.deleteDirectory(file);
    } catch (IOException ex) {
        Logger.getLogger(NewEntryTextControllerTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:dao.NewEntryTextDaoTest.java

@AfterClass
public static void tearDownClass() {
    File file = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook");
    try {/*  ww w  .j  av  a  2s  .com*/
        FileUtils.deleteDirectory(file);
    } catch (IOException ex) {
        Logger.getLogger(NewEntryTextDaoTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.xiaomi.linden.core.ZooKeeperService.java

public static synchronized void start() {
    if (zkServer == null) {
        File file = new File(ZK_DATA_DIR);
        if (file.exists()) {
            try {
                FileUtils.deleteDirectory(new File(ZK_DATA_DIR));
            } catch (IOException e) {
                e.printStackTrace();//ww w . j av a2  s  .  c o m
            }
        }
        zkServer = new EmbeddedZooKeeper(file, 2181);
        try {
            zkServer.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}