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.seleniumtests.ut.util.squashta.TestTaFolderStructureGenerator.java

/**
 * folder structure generation with ta file present in source. We check that it's taken
 * @throws IOException//from ww w . ja  v a2  s  . c  o  m
 */
@Test(groups = { "squash" })
public void testGenerateStructureWithExistingTa() throws IOException {
    File tmpFolder = Paths.get(SeleniumTestsContextManager.getDataPath(), "tmp").toFile();
    File taFile = Paths.get(tmpFolder.getPath(), "src", "squashTA", "tests", "core_generic.ta").toFile();
    FileUtils.writeStringToFile(taFile, "exists");

    TaFolderStructureGenerator structGen = new TaFolderStructureGenerator("core", tmpFolder.getAbsolutePath(),
            tmpFolder.getAbsolutePath());
    try {
        structGen.generateDefaultStructure();
        Assert.assertTrue(taFile.exists());
        Assert.assertEquals(FileUtils.readFileToString(taFile), "exists");
    } finally {
        FileUtils.cleanDirectory(tmpFolder);
        tmpFolder.delete();
    }
}

From source file:com.huawei.streaming.cql.CQLTestCommons.java

/**
 * ??/*from  w w w. j  a  v  a 2  s .com*/
 *
 * @param dir 
 * @throws IOException ?
 */
public static void emptyDir(File dir) throws IOException {
    if (!dir.isDirectory()) {
        return;
    }
    FileUtils.cleanDirectory(dir);
}

From source file:ddf.catalog.cache.impl.ResourceCacheTest.java

@After
public void teardownTest() {
    try {//w w  w. j  a  v  a 2 s .  c o m
        FileUtils.cleanDirectory(new File(defaultProductCacheDirectory));
    } catch (IOException e) {
        LOGGER.warn("unable to clean directory");
    }
}

From source file:com.funambol.server.config.ConfigurationTest.java

@Override
protected void setUp() throws Exception {
    File initialPlugin = new File(funambolHome,
            "com/funambol/server/config/Configuration/plugin/initial-plugins");

    FileUtils.forceMkdir(runtimePluginDir);
    FileUtils.cleanDirectory(runtimePluginDir);
    FileUtils.copyDirectory(initialPlugin, runtimePluginDir, new WildcardFileFilter("*.xml"));

    ////from  w w w .  j a va 2s  .  c o m
    // This is required since if the plugin xml files used in the tests are 
    // downloaded from SVN repository, they have the same timestamp so the changes
    // are not correctly detected by the DirectoryMonitor. In this way we are sure
    // the timestamp is different (touch uses the current timestamp and of course the
    // files - in src/test/data/com/funambol/server/config/Configuration/pluging/test-1 -
    // are downloaded previously)
    //
    File[] files = runtimePluginDir.listFiles();
    for (File file : files) {
        FileUtils.touch(file);
    }

    Configuration.getConfiguration();
}

From source file:com.goodformobile.build.mobile.AbstractRIMMojoTest.java

protected File setupCleanCopyOfProject(File projectDirectory) throws IOException {
    File workProjectDirectory = new File(getBasedir(), "target/temp/project");
    if (workProjectDirectory.exists()) {
        FileUtils.cleanDirectory(workProjectDirectory);
    }/* w  w w  . ja v  a2s .  c  om*/
    FileUtils.copyDirectory(projectDirectory, workProjectDirectory);
    return workProjectDirectory;
}

From source file:edu.uci.ics.pregelix.example.jobrun.RunJobTestSuite.java

public void setUp() throws Exception {
    ClusterConfig.setStorePath(PATH_TO_CLUSTER_STORE);
    ClusterConfig.setClusterPropertiesPath(PATH_TO_CLUSTER_PROPERTIES);
    cleanupStores();//w w  w.  j ava 2  s . c  o  m
    PregelixHyracksIntegrationUtil.init();
    LOGGER.info("Hyracks mini-cluster started");
    FileUtils.forceMkdir(new File(ACTUAL_RESULT_DIR));
    FileUtils.cleanDirectory(new File(ACTUAL_RESULT_DIR));
    startHDFS();
}

From source file:it.greenvulcano.util.file.FileManager.java

/**
 * Delete the file/directory from the local file system.<br>
 * The filePattern may be a regular expression: in this case, all
 * the file names matching the pattern will be deleted.<br>
 *
 * @param targetPath/*www. j  a va2s.c o m*/
 *            Absolute pathname of the target file/directory.
 * @param filePattern
 *            A regular expression defining the name of the files to be deleted. Used only if
 *            targetPath identify a directory.
 * @throws Exception
 */
public static void rm(String targetPath, String filePattern) throws Exception {
    File target = new File(targetPath);
    if (!target.isAbsolute()) {
        throw new IllegalArgumentException("The pathname of the target file is NOT absolute: " + targetPath);
    }
    if (target.isDirectory()) {
        if ((filePattern == null) || filePattern.equals("")) {
            logger.debug("Removing directory " + target.getAbsolutePath());
            FileUtils.deleteDirectory(target);
        } else if (filePattern.equals(".*")) {
            logger.debug("Removing directory " + target.getAbsolutePath() + " content.");
            FileUtils.cleanDirectory(target);
        } else {
            Set<FileProperties> files = ls(targetPath, filePattern);
            for (FileProperties file : files) {
                logger.debug("Removing file/directory " + file.getName() + " from directory "
                        + target.getAbsolutePath());
                FileUtils.forceDelete(new File(target, file.getName()));
            }
        }
    } else {
        logger.debug("Removing file " + target.getAbsolutePath());
        FileUtils.forceDelete(target);
    }
}

From source file:co.runrightfast.vertx.orientdb.plugins.OrientDBHazelcastPluginTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    System.setProperty("config.resource", String.format("%s.conf", CLASS_NAME));
    ConfigFactory.invalidateCaches();//from   ww  w  .  ja v a  2s. co m
    final Config typesafeConfig = ConfigFactory.load();
    hazelcast = Hazelcast.newHazelcastInstance(HazelcastConfigFactory.hazelcastConfigFactory("OrientDB")
            .apply(typesafeConfig.getConfig("hazelcast")));
    OrientDBPluginWithProvidedHazelcastInstance.HAZELCAST_INSTANCE = () -> hazelcast;

    orientdbHome.mkdirs();
    FileUtils.cleanDirectory(orientdbHome);
    FileUtils.deleteDirectory(orientdbHome);
    log.logp(INFO, CLASS_NAME, "setUpClass",
            String.format("orientdbHome.exists() = %s", orientdbHome.exists()));

    final File configDirSrc = new File("src/test/resources/orientdb/config");
    final File configDirTarget = new File(orientdbHome, "config");
    FileUtils.copyFileToDirectory(new File(configDirSrc, "default-distributed-db-config.json"),
            configDirTarget);
    FileUtils.copyFileToDirectory(new File(configDirSrc, "hazelcast.xml"), configDirTarget);

    final ApplicationId appId = ApplicationId.builder().group("co.runrightfast")
            .name("runrightfast-vertx-orientdb").version("1.0.0").build();
    final AppEventLogger appEventLogger = new AppEventJDKLogger(appId);

    final EmbeddedOrientDBServiceConfig config = EmbeddedOrientDBServiceConfig.builder()
            .orientDBRootDir(orientdbHome.toPath()).handler(OrientDBHazelcastPluginTest::oGraphServerHandler)
            .handler(OrientDBHazelcastPluginTest::oHazelcastPlugin)
            .handler(OrientDBHazelcastPluginTest::oServerSideScriptInterpreter)
            .networkConfig(oServerNetworkConfiguration())
            .user(new OServerUserConfiguration(ROOT_USER, "root", "*"))
            .property(OGlobalConfiguration.DB_POOL_MIN, "1").property(OGlobalConfiguration.DB_POOL_MAX, "50")
            .databasePoolConfig(
                    new OrientDBPoolConfig(CLASS_NAME, String.format("remote:localhost/%s", CLASS_NAME),
                            "admin", "admin", 10, ImmutableSet.of(() -> new SetCreatedOnAndUpdatedOn())))
            .lifecycleListener(() -> new RunRightFastOrientDBLifeCycleListener(appEventLogger)).build();

    service = new EmbeddedOrientDBService(config);
    ServiceUtils.start(service);
    initDatabase();
}

From source file:com.eufar.asmm.server.DownloadFunction.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println("DownloadFunction - the function started");
    ServletContext context = getServletConfig().getServletContext();
    request.setCharacterEncoding("UTF-8");
    String dir = context.getRealPath("/tmp");
    ;/*from  w ww  .jav  a  2  s  .  c  o m*/
    String filename = "";
    File fileDir = new File(dir);
    try {
        System.out.println("DownloadFunction - create the file on server");
        filename = request.getParameterValues("filename")[0];
        String xmltree = request.getParameterValues("xmltree")[0];

        // format xml code to pretty xml code
        Document doc = DocumentHelper.parseText(xmltree);
        StringWriter sw = new StringWriter();
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setIndent(true);
        format.setIndentSize(4);
        XMLWriter xw = new XMLWriter(sw, format);
        xw.write(doc);

        Writer out = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(dir + "/" + filename), "UTF-8"));
        out.append(sw.toString());
        out.flush();
        out.close();
    } catch (Exception ex) {
        System.out.println("ERROR during rendering: " + ex);
    }
    try {
        System.out.println("DownloadFunction - send file to user");
        ServletOutputStream out = response.getOutputStream();
        File file = new File(dir + "/" + filename);
        String mimetype = context.getMimeType(filename);
        response.setContentType((mimetype != null) ? mimetype : "application/octet-stream");
        response.setContentLength((int) file.length());
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        response.setHeader("Pragma", "private");
        response.setHeader("Cache-Control", "private, must-revalidate");
        DataInputStream in = new DataInputStream(new FileInputStream(file));
        int length;
        while ((in != null) && ((length = in.read(bbuf)) != -1)) {
            out.write(bbuf, 0, length);
        }
        in.close();
        out.flush();
        out.close();
        FileUtils.cleanDirectory(fileDir);
    } catch (Exception ex) {
        System.out.println("ERROR during downloading: " + ex);
    }
    System.out.println("DownloadFunction - file ready to be donwloaded");
}

From source file:de.mpg.imeji.test.logic.storage.StorageTest.java

@Before
public void cleanFiles() {
    try {//www  . j a  va2  s .  c  o m
        Imeji.CONFIG = new ImejiConfiguration();
        File f = new File(PropertyReader.getProperty("imeji.storage.path"));
        if (f.exists())
            FileUtils.cleanDirectory(f);
    } catch (Exception e) {
        LOGGER.error("CleanFiles error", e);
    }
}