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

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

Introduction

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

Prototype

public static void cleanDirectory(File directory) throws IOException 

Source Link

Document

Cleans a directory without deleting it.

Usage

From source file:com.hpl.mds.annotations.processors.JCompiler.java

private JCompiler() {
    try {//from w w  w.  ja v a 2  s.  c  o m
        Path outputPath = Paths.get(OUTPUT_DIR);
        File outputDirFile = outputPath.toFile();
        if (outputDirFile.exists()) {
            FileUtils.cleanDirectory(outputDirFile);
        }
        URL url = outputDirFile.toURI().toURL();
        CLASS_LOADER = new URLClassLoader(new URL[] { url });
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.buddycloud.mediaserver.download.DownloadMediasInfoTest.java

private void storeFile(String id) throws Exception {
    File destDir = new File(configuration.getProperty(MediaServerConfiguration.MEDIA_STORAGE_ROOT_PROPERTY)
            + File.separator + BASE_CHANNEL);

    if (!destDir.mkdir()) {
        FileUtils.cleanDirectory(destDir);
    }/* w  w  w.ja v a 2  s  .  c  om*/

    FileUtils.copyFile(new File(TEST_FILE_PATH + TEST_IMAGE_NAME), new File(destDir + File.separator + id));

    Media media = buildMedia(id, TEST_FILE_PATH + TEST_IMAGE_NAME);
    dataSource.storeMedia(media);
}

From source file:edu.usc.irds.agepredictor.spark.authorage.AgePredictSGDTrainer.java

public static void generateEvents(SparkSession spark, String dataIn, String tokenizer, String featureGenerators,
        String outDir) throws IOException {

    AgeClassifyContextGeneratorWrapper wrapper = new AgeClassifyContextGeneratorWrapper(tokenizer,
            featureGenerators);//  w ww .  jav a 2 s  .  c  om

    JavaRDD<String> data = spark.sparkContext().textFile(dataIn, 48).toJavaRDD().cache();

    JavaRDD<EventWrapper> samples = data.map(new CreateEvents(wrapper)).cache();

    JavaRDD<EventWrapper> validSamples = samples.filter(new Function<EventWrapper, Boolean>() {
        @Override
        public Boolean call(EventWrapper s) {
            if (s != null) {
                return s.getValue() != null;
            }
            return false;
        }
    }).repartition(8);

    File dir = new File(outDir);
    if (dir.exists()) {
        FileUtils.cleanDirectory(dir); //clean out directory (this is optional -- but good know)
        FileUtils.forceDelete(dir); //delete directory
    }

    validSamples.saveAsTextFile(outDir);
}

From source file:edu.purdue.cybercenter.dm.web.GlobusControllerTest.java

public static void setUpClass() throws Exception {
    File source1 = new File("./src/test/files/" + FILE_TO_UPLOAD_1);
    File source2 = new File("./src/test/files/" + FILE_TO_UPLOAD_2);
    File source3 = new File("./src/test/files/" + FILE_TO_DOWNLOAD_1);

    String remoteEndpointDir = STORAGE_ROOT + REMOTE_ENDPOINT;
    File destDir = new File(remoteEndpointDir);

    FileUtils.copyFileToDirectory(source1, destDir, true);
    FileUtils.copyFileToDirectory(source2, destDir, true);

    String storageDir = STORAGE_ROOT + GLOBUS_STORAGE_DIRECTORY;
    destDir = new File(storageDir);

    if (destDir.exists() && destDir.isDirectory()) {
        FileUtils.copyFileToDirectory(source3, destDir, true);
    }/*  w  w w .j a  v a 2 s  .  co  m*/

    FileUtils.cleanDirectory(new File(STORAGE_ROOT + GLOBUS_STORAGE_WORKEAERA_DIRECTORY));
}

From source file:com.netflix.conductor.dao.es5.es.EmbeddedElasticSearch.java

public static void cleanDataDir(String path) {
    try {//from  w  w  w . j av a 2  s. c  o  m
        logger.info("Deleting contents of data dir {}", path);
        File f = new File(path);
        if (f.exists()) {
            FileUtils.cleanDirectory(new File(path));
        }
    } catch (IOException e) {
        logger.error("Failed to delete ES data dir");
    }
}

From source file:com.linkedin.restli.tools.idlgen.TestRestLiResourceModelExporter.java

@BeforeMethod
public void testSetup() throws IOException {
    FileUtils.cleanDirectory(outdir);
}

From source file:at.uni_salzburg.cs.ros.viewer.services.BigraphReactionRuleArchiveImpl.java

/**
 * @param imageRenderer the BigraphImageRenderer instance.
 * @throws IOException//w w w  .  ja  v  a2 s. c  om
 */
public BigraphReactionRuleArchiveImpl(BigraphImageRenderer imageRenderer) throws IOException {
    this.imageRenderer = imageRenderer;
    String brrArchiveDirName = System.getProperty(BRR_ARCHIVE_PROP, BRR_ARCHIVE_DEFAULT_DIR);
    brrArchive = new File(brrArchiveDirName);
    FileUtils.forceMkdir(brrArchive);
    LOG.info("Using archive directory {}", brrArchive.getAbsolutePath());

    String cleanUp = System.getProperty(BRR_ARCHIVE_CLEANUP_PROP, "true");
    if ("true".equalsIgnoreCase(cleanUp)) {
        LOG.info("Cleaning up bigraph image archive folder '{}'", brrArchive.getAbsolutePath());
        FileUtils.cleanDirectory(brrArchive);
    } else {
        LOG.info("Cleaning up bigraph image archive folder '{}' declined.", brrArchive.getAbsolutePath());
    }
}

From source file:com.groupcdg.maven.tidesdk.GenerateMojoTest.java

@Test
public void testCustomResourcesGeneration() throws Exception {
    File target = new File(CUSTOM_RESOURCES_PROJECT, "target");
    if (target.exists())
        FileUtils.cleanDirectory(target);

    rule.configureMojo(new GenerateMojo(), PLUGIN_NAME, pom(CUSTOM_RESOURCES_PROJECT));
    rule.executeMojo(CUSTOM_RESOURCES_PROJECT, GENERATE_GOAL);

    assertIncluded(config(CUSTOM_RESOURCES_PROJECT, "manifest"), "appname: Custom_Resources_Project");
    assertIncluded(config(CUSTOM_RESOURCES_PROJECT, "tiapp.xml"), "<name>Custom Resources Project</name>");
    assertIncluded(asset(CUSTOM_RESOURCES_PROJECT, "index.html"), CUSTOM_ASSET_CONTENT);
    assertIncluded(asset(CUSTOM_RESOURCES_PROJECT, "css/style.css"), CUSTOM_ASSET_CONTENT);
    assertIncluded(asset(CUSTOM_RESOURCES_PROJECT, "other.html"), OVERRIDEN_ASSET_CONTENT);
    assertExcluded(asset(CUSTOM_RESOURCES_PROJECT, "excluded.txt"));
}

From source file:dbseer.comp.process.live.LiveLogProcessor.java

public void start() throws Exception {
    liveLogExecutor = Executors.newCachedThreadPool();
    sysStartTime = 0;/* www .  j a  v a 2  s .  co  m*/
    txStartTime = 0;

    // check live directory
    File liveDir = new File(dir);
    if (!liveDir.exists()) {
        // create directories if it does not exist.
        liveDir.mkdirs();
    }

    // start sys log processors
    servers = serverStr.split(MiddlewareConstants.SERVER_STRING_DELIMITER);
    for (String server : servers) {
        FileUtils.forceMkdir(new File(dir + File.separator + server));
        FileUtils.cleanDirectory(new File(dir + File.separator + server));
        File sysFile = new File(dir + File.separator + "sys.log." + server);
        SystemLogProcessor sysLogProcessor;
        if (DBSeerGUI.osType == DBSeerConstants.OS_LINUX) {
            sysLogProcessor = new DstatSystemLogProcessor(dir + File.separator + server, this);
        } else {
            sysLogProcessor = new DstatSystemLogProcessor(dir + File.separator + server, this);
        }
        sysLogProcessor.initialize();
        LiveLogTailer sysLogTailerListener = new LiveLogTailer(sysLogProcessor);
        LogTailer sysLogTailer = new LogTailer(sysFile, sysLogTailerListener, 250, 0, false);

        liveLogExecutor.submit(sysLogTailer);
    }

    // start tx log processors
    TransactionLogProcessor txLogProcessor;
    if (DBSeerGUI.databaseType == DBSeerConstants.DB_MYSQL) {
        txLogProcessor = new MySQLTransactionLogProcessor(DBSeerGUI.settings.mysqlLogDelimiter,
                DBSeerGUI.settings.mysqlQueryDelimiter);
    } else {
        txLogProcessor = new MySQLTransactionLogProcessor(DBSeerGUI.settings.mysqlLogDelimiter,
                DBSeerGUI.settings.mysqlQueryDelimiter);
    }
    File txLogFile = new File(dir + File.separator + "tx.log");
    LiveLogTailer txLogTailerListener = new LiveLogTailer(txLogProcessor);
    LogTailer txLogTailer = new LogTailer(txLogFile, txLogTailerListener, 250, 0, false);

    transactionLogWriter = new TransactionLogWriter(dir, servers, DBSeerGUI.liveMonitorInfo, this);
    transactionLogWriter.initialize();

    liveTransactionLogWriter = new LiveTransactionLogWriter(txLogProcessor, transactionLogWriter);
    liveMonitor = new LiveMonitor();

    liveLogExecutor.submit(txLogTailer);
    liveLogExecutor.submit(liveTransactionLogWriter);
    liveLogExecutor.submit(liveMonitor);
    this.isStarted = true;
}

From source file:com.synconset.ImageFetcher.java

public ImageFetcher(Context ct) {
    context = ct;/*from  w  ww. j av a  2  s . co m*/
    executor = Executors.newCachedThreadPool();

    dir_thumb = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "thumb");
    if (!dir_thumb.isDirectory() && !dir_thumb.mkdir()) {
        // failed
    }

    try {
        FileUtils.cleanDirectory(dir_thumb);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}