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:org.digidoc4j.ConfigurationTest.java

@SuppressWarnings("ConstantConditions")
@Test/*w w  w. j  a va2s .c  om*/
public void clearTSLCache() throws Exception {
    Configuration myConfiguration = new Configuration(TEST);
    File fileCacheDirectory = TslLoader.fileCacheDirectory;
    if (fileCacheDirectory.exists()) {
        FileUtils.cleanDirectory(fileCacheDirectory);
    }

    TSLCertificateSource tslCertificateSource = myConfiguration.getTSL();
    tslCertificateSource.refresh();
    waitOneSecond();
    File oldCachedFile = fileCacheDirectory.listFiles()[0];
    FileTime oldCachedFileDate = (FileTime) Files.getAttribute(oldCachedFile.toPath(), "basic:creationTime");

    tslCertificateSource.invalidateCache();
    myConfiguration.setTSL(null);
    tslCertificateSource = myConfiguration.getTSL();
    tslCertificateSource.refresh();

    File newCachedFile = fileCacheDirectory.listFiles()[0];
    FileTime newCachedFileDate = (FileTime) Files.getAttribute(newCachedFile.toPath(), "basic:creationTime");

    assertTrue(newCachedFileDate.compareTo(oldCachedFileDate) > 0);
}

From source file:org.digidoc4j.impl.bdoc.tsl.TslLoader.java

public static void invalidateCache() {
    logger.info("Cleaning TSL cache directory at " + fileCacheDirectory.getPath());
    try {//from w  w w.  j  a  va  2 s.c o m
        if (fileCacheDirectory.exists()) {
            FileUtils.cleanDirectory(fileCacheDirectory);
        } else {
            logger.debug("TSL cache directory doesn't exist");
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
        throw new DigiDoc4JException(e);
    }
}

From source file:org.digidoc4j.impl.bdoc.TslLoader.java

public void invalidateCache() {
    try {/*from  ww w.  j  a  v a 2  s  . c o m*/
        FileUtils.cleanDirectory(fileCacheDirectory);
    } catch (Exception e) {
        logger.error(e.getMessage());
        throw new DigiDoc4JException(e);
    }
}

From source file:org.digidoc4j.TSLCertificateSource.java

/**
 * Invalidates cache and reloads TSL./*  w  ww .  ja v a2s  . c om*/
 *
 * Only applicable when cache is used.
 *
 */
public void invalidateCache() {
    logger.debug("");
    if (dataLoader instanceof FileCacheDataLoader) {
        try {
            FileUtils.cleanDirectory(fileCacheDirectory);
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new DigiDoc4JException(e);
        }
        init();
    }
}

From source file:org.dkf.jmule.MainApplication.java

private void cleanTemp() {
    try {/*from  w  w  w  .  j  a  v a 2s  .  c o  m*/
        File tmp = Platforms.get().systemPaths().temp();
        if (tmp.exists()) {
            FileUtils.cleanDirectory(tmp);
        }
    } catch (Exception e) {
        LOG.error("Error during setup of temp directory", e);
    }
}

From source file:org.drools.workbench.jcr2vfsmigration.MortgagesRepoImportTest.java

@Before
public void setup() throws Exception {
    FileUtils.deleteDirectory(outputVfsRepo);
    FileUtils.forceMkdir(jcrExportDir);//from  ww w . j  av a  2 s.c  o  m
    FileUtils.cleanDirectory(jcrExportDir);
    File jcrExportZip = new File(Class.class.getResource("/jcr-export-xml.zip").getFile());
    unzipFile(jcrExportZip, jcrExportDir);
}

From source file:org.duniter.client.Main.java

protected void initI18n() throws IOException {
    Configuration config = Configuration.instance();

    // --------------------------------------------------------------------//
    // init i18n//from   w  w  w.ja  v a 2s.  c  o  m
    // --------------------------------------------------------------------//
    File i18nDirectory = config.getI18nDirectory();
    if (i18nDirectory.exists()) {
        // clean i18n cache
        FileUtils.cleanDirectory(i18nDirectory);
    }

    FileUtils.forceMkdir(i18nDirectory);

    if (debug) {
        System.out.println("INFO - I18N directory: " + i18nDirectory);
    }

    Locale i18nLocale = config.getI18nLocale();

    // Fix locale
    if (i18nLocale.equals(Locale.FRENCH)) {
        i18nLocale = Locale.FRANCE;
    } else if (i18nLocale.equals(Locale.ENGLISH)) {
        i18nLocale = Locale.UK;
    }

    if (debug) {
        System.out.println(
                String.format("INFO - Starts i18n with locale [%s] at [%s]", i18nLocale, i18nDirectory));
    }
    I18n.init(new UserI18nInitializer(i18nDirectory, new DefaultI18nInitializer(getI18nBundleName())),
            i18nLocale);
}

From source file:org.duniter.elasticsearch.PluginSettings.java

protected void initI18n() throws IOException {
    //if (I18n.getDefaultLocale() != null) return; // already init

    // --------------------------------------------------------------------//
    // init i18n//from  w w w  .j a  v a 2  s .c o m
    // --------------------------------------------------------------------//

    File i18nDirectory = clientConfig.getI18nDirectory();
    if (i18nDirectory.exists()) {
        // clean i18n cache
        FileUtils.cleanDirectory(i18nDirectory);
    }

    FileUtils.forceMkdir(i18nDirectory);

    if (logger.isDebugEnabled()) {
        logger.debug("I18N directory: " + i18nDirectory);
    }

    Locale i18nLocale = clientConfig.getI18nLocale();

    if (logger.isInfoEnabled()) {
        logger.info(String.format("Starts i18n with locale [%s] at [%s]", i18nLocale, i18nDirectory));
    }

    I18n.init(new I18nInitializer(i18nDirectory, getI18nBundleNames()), i18nLocale);
}

From source file:org.duracloud.syncoptimize.data.TestDataHandler.java

public void createDirectories(File... dirs) throws IOException {
    for (File dir : dirs) {
        if (dir.exists()) {
            try {
                FileUtils.cleanDirectory(dir);
            } catch (IOException e) {
                log.warn("Unable to clean directory {} due to  {}", dir.getAbsolutePath(), e.getMessage());
            }//from ww w . ja va  2  s  .co m
        } else {
            FileUtils.forceMkdir(dir);
        }
    }
}

From source file:org.duracloud.syncoptimize.data.TestDataHandler.java

public void removeDirectories(File... dirs) throws IOException {
    for (File dir : dirs) {
        try {//  w  ww  .ja v  a 2s  .  c  om
            FileUtils.deleteDirectory(dir);
        } catch (IOException e) {
            try {
                FileUtils.cleanDirectory(dir);
            } catch (IOException e2) {
                log.warn("Unable to clean directory {} due to  {}", dir.getAbsolutePath(), e2.getMessage());
            }
        }
    }
}