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.garethahealy.camel.file.loadbalancer.example1.routes.HandlesOneFileMultipleReadersTest.java

@Override
protected void doPreSetup() throws Exception {
    File directory = FileUtils.toFile(new URL("file:" + rootDirectory));
    FileUtils.deleteDirectory(directory);

    directory.mkdir();//from  ww w . ja  va  2 s  . co  m

    URL file1 = HandlesOneFileMultipleReadersTest.class.getClassLoader()
            .getResource("example-files/afile1.log");

    Assert.assertNotNull(file1);

    FileUtils.copyFileToDirectory(FileUtils.toFile(file1), directory);

    LOG.info("Moved files to: " + directory.getAbsolutePath());
}

From source file:com.scaleunlimited.cascading.DatumCompilerTest.java

@Test
public void testSimpleSchema() throws Exception {
    CompiledDatum result = DatumCompiler.generate(MyDatumTemplate.class);

    File baseDir = new File("build/test/DatumCompilerTest/testSimpleSchema/");
    FileUtils.deleteDirectory(baseDir);
    File srcDir = new File(baseDir, result.getPackageName().replaceAll("\\.", "/"));
    assertTrue(srcDir.mkdirs());// w  w  w  .j a v a  2s  .  c  o  m

    File codeFile = new File(srcDir, result.getClassName() + ".java");
    OutputStream os = new FileOutputStream(codeFile);
    IOUtils.write(result.getClassCode(), os, "UTF-8");
    os.close();

    // Compile with Janino, give it a try. We have Janino since
    // it's a cascading dependency, but probably want to add a test
    // dependency on it.

    ClassLoader cl = new JavaSourceClassLoader(this.getClass().getClassLoader(), // parentClassLoader
            new File[] { baseDir }, // optionalSourcePath
            (String) null // optionalCharacterEncoding
    );

    // WARNING - we have to use xxxDatumTemplate as the base name, so that the code returned
    // by the compiler is for type xxxDatum. Otherwise when we try to load the class here,
    // we'll likely get the base (template) class, which will mask our generated class.
    Class clazz = cl.loadClass(result.getPackageName() + "." + result.getClassName());
    assertEquals("MyDatum", clazz.getSimpleName());

    // Verify that we have a constructor which takes all of the fields.
    //        private String _name;
    //        private int ageAndRisk;
    //        private Date _date;
    //        private Tuple _aliases;
    //        private String[] _phoneNumbers
    // private MyDatumEnum _enum

    Constructor c = clazz.getConstructor(String.class, int.class, Date.class, Tuple.class, String[].class,
            MyDatumEnum.class);
    BaseDatum datum = (BaseDatum) c.newInstance("robert", 25, new Date(), new Tuple("bob", "rob"),
            new String[] { "555-1212", "555-4848" }, MyDatumEnum.DATUM_COMPILER_ENUM_2);

    // Verify that it can be serialized with Hadoop.
    // TODO figure out why Hadoop serializations aren't available???
    /*
    BasePlatform testPlatform = new HadoopPlatform(DatumCompilerTest.class);
    Tap tap = testPlatform.makeTap( testPlatform.makeBinaryScheme(datum.getFields()), 
                testPlatform.makePath("build/test/DatumCompilerTest/testSimpleSchema/"));
    TupleEntryCollector writer = tap.openForWrite(testPlatform.makeFlowProcess());
    writer.add(datum.getTuple());
    writer.close();
            
    TupleEntryIterator iter = tap.openForRead(testPlatform.makeFlowProcess());
    TupleEntry te = iter.next();
            
    // TODO how to test round-trip?
     */
}

From source file:com.netflix.imfutility.itunes.metadata.film.FilmMetadataXmlProviderTest.java

@BeforeClass
public static void setupAll() throws IOException {
    // create both working directory and logs folder.
    FileUtils.deleteDirectory(TemplateParameterContextCreator.getWorkingDir());
    File workingDir = TemplateParameterContextCreator.getWorkingDir();
    if (!workingDir.mkdir()) {
        throw new RuntimeException("Could not create a working dir within tmp folder");
    }// w  w  w  .ja  v a 2s  . c  o m

    try {
        context = JAXBContext.newInstance(PackageType.class);
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
}

From source file:bixo.examples.crawl.LatestUrlDatumBufferTest.java

@Before
public void setUp() throws IOException {

    File workingFolder = new File(WORKINGDIR);
    if (workingFolder.exists()) {
        FileUtils.deleteDirectory(workingFolder);
    }/*  w w  w .  ja  v a  2  s.  c  o  m*/
}

From source file:com.kylinolap.job.hadoop.cube.CubeReducerTest.java

@Before
public void setUp() throws Exception {
    createTestMetadata();//from www.ja v  a  2s .  c  o m

    // hack for distributed cache
    FileUtils.deleteDirectory(new File("../job/meta"));
    FileUtils.copyDirectory(new File(this.getTestConfig().getMetadataUrl()), new File("../job/meta"));

    CuboidReducer reducer = new CuboidReducer();
    reduceDriver = ReduceDriver.newReduceDriver(reducer);
}

From source file:com.srotya.tau.api.dao.alertreceiver.DatabaseResource.java

@Override
protected void before() throws Throwable {
    java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.OFF);
    Properties config = new Properties(System.getProperties());
    File db = new File(TARGET_RULES_DB);
    if (db.exists()) {
        FileUtils.deleteDirectory(db);
    }//from   www. java2s. c o m
    config.setProperty("javax.persistence.jdbc.url", CONNECTION_STRING);
    try {
        emf = Persistence.createEntityManagerFactory("tau", config);
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }

    EntityManager em = emf.createEntityManager();

    RuleGroup ruleGroup = new RuleGroup();
    ruleGroup.setRuleGroupId("all");
    ruleGroup.setRuleGroupName("all");
    RuleGroupManager.getInstance().createRuleGroup(em, ruleGroup);
}

From source file:it.neo4art.api.search.repository.WikipediaSearchRepositoryTest.java

@Before
public void cleanDatabase() throws IOException {

    FileUtils.deleteDirectory(new File(GraphDatabaseConnectionManager.NEO4J_STORE_DIR));
}

From source file:eu.europa.ejusticeportal.dss.applet.model.service.FileSeekerTest.java

@BeforeClass
public static void setUpTestFileStructure() throws IOException, InterruptedException {

    assertTrue(s != null && s.length() != 0);
    assertTrue(home.exists());/*w  w  w  . j a  v  a  2s .  c  om*/
    File testFileStructure = new File(home, "dss_applet_test/aaa/bb bb/cc ccc/ddd dd");

    if (testFileStructure.exists()) {
        FileUtils.deleteDirectory(testFileStructure);
    }
    testFileStructure = new File(home, "dss_applet_test/aaa/bb bb/cc ccc/ddd dd");
    if (!testFileStructure.exists()) {
        testFileStructure.mkdirs();
    }
    assertTrue(testFileStructure.exists());
    File library = new File(testFileStructure, "library.dll");
    if (!library.exists()) {
        library.createNewFile();
    }
    assertTrue(library.exists());

    File library2Folder = new File(home, "dss_applet_test/aaa");
    File library2 = new File(library2Folder, "pkcs11.so");
    if (!library2.exists()) {
        library2.createNewFile();
    }
    assertTrue(library2.exists());

    File library3Folder = new File(home, "dss_applet_test/aaa/bb bb/cc ccc");
    File library3 = new File(library3Folder, "pkcs11.so");
    if (!library3.exists()) {
        library3.createNewFile();
    }
    assertTrue(library3.exists());

    try {
        //Show the directory structure we created
        ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/C", "tree", "/a", "/F",
                new File(home, "dss_applet_test").getAbsolutePath());

        Process p = pb.start();
        InputStreamReader isr = new InputStreamReader(p.getInputStream(), Charset.forName("US-ASCII"));
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            log(line);
        }
    } catch (Exception e) {
        log(e.getMessage());
    }
}

From source file:mesclasses.util.EleveFileUtil.java

public static void deleteFilesForEleve(Eleve eleve) {
    try {/*from   w w  w . j ava  2 s .c o  m*/
        FileUtils.deleteDirectory(getEleveDir(eleve));
    } catch (IOException ex) {
        AppLogger.notif("Suppression de fichiers", ex);
    }
}

From source file:com.twitter.heron.uploader.localfs.LocalFileSystemUploaderTest.java

@After
public void after() throws Exception {
    FileUtils.deleteDirectory(new File(fileSystemDirectory));
}