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.francelabs.datafari.servlets.admin.ZooKeeperConf.java

/**
 * @throws IOException/*from ww w  .j  a v a2s . c o  m*/
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)
 */
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    final JSONObject jsonResponse = new JSONObject();
    request.setCharacterEncoding("utf8");
    response.setContentType("application/json");
    final String actionParam = request.getParameter("action");

    IndexerServer server = null;
    try {
        server = IndexerServerManager.getIndexerServer(Core.FILESHARE);
    } catch (final IOException e1) {
        final PrintWriter out = response.getWriter();
        out.append(
                "Error while getting the Solr core, please make sure the core dedicated to PromoLinks has booted up. Error code : 69000");
        out.close();
        LOGGER.error(
                "Error while getting the Solr core in doGet, admin servlet, make sure the core dedicated to Promolink has booted up and is still called promolink or that the code has been changed to match the changes. Error 69000 ",
                e1);
        return;

    } catch (final Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        if (actionParam.toLowerCase().equals("download")) {
            final File folderConf = new File(downloadFolder);
            FileUtils.cleanDirectory(folderConf);
            server.downloadConfig(Paths.get(downloadFolder), Core.FILESHARE.toString());
        } else if (actionParam.toLowerCase().equals("upload")) {
            server.uploadConfig(Paths.get(env), Core.FILESHARE.toString());
        } else if (actionParam.toLowerCase().equals("reload")) {
            server.reloadCollection(Core.FILESHARE.toString());
        } else if (actionParam.toLowerCase().equals("upload_and_reload")) {
            server.uploadConfig(Paths.get(env), Core.FILESHARE.toString());
            Thread.sleep(3000);
            server.reloadCollection(Core.FILESHARE.toString());
        }

        jsonResponse.put(OutputConstants.CODE, CodesReturned.ALLOK.getValue());
    } catch (final IOException | SolrServerException | InterruptedException e) {
        LOGGER.error("Exception during action " + actionParam, e);
        jsonResponse.put(OutputConstants.CODE, CodesReturned.GENERALERROR.getValue());
    }
    final PrintWriter out = response.getWriter();
    out.print(jsonResponse);
}

From source file:com.funambol.server.cleanup.ClientLogCleanUpAgentTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    agent = new ClientLogCleanUpAgent(clientsLogDir, targetArchivationDirectory, activationThreshold,
            maxNumberOfArchivedFiles, numberOfArchivedFilesToDelete, timeToRest, lockName);

    try {//from  w  ww. j a v  a  2s.c  om
        FileUtils.forceMkdir(new File(TARGET_DIR));
        FileUtils.cleanDirectory(new File(TARGET_DIR));
        FileUtils.copyDirectory(new File(BASE_DIR), new File(TARGET_DIR),
                new NotFileFilter(new SuffixFileFilter(".svn")));
    } catch (IOException e) {
        assertTrue("Unable to handle target dir", true);
    }
}

From source file:com.indoqa.osgi.embedded.test.integration.OSGiEmbeddedIntegrationTest.java

private Path prepareDirectory(String dir) throws IOException {
    Path path = Paths.get(dir);
    Files.createDirectories(path);
    FileUtils.cleanDirectory(path.toFile());
    return path;/*from w w  w  .  j  a  v  a  2 s.  c  o m*/
}

From source file:net.sourceforge.atunes.kernel.modules.audioscrobbler.AudioScrobblerCache.java

/**
 * Clears the cache/*  w  w w .  j a  v  a 2s. c o m*/
 * 
 * @return If an IOException occured during clearing
 */
public static synchronized boolean clearCache() {
    boolean exception = false;
    try {
        FileUtils.cleanDirectory(albumCoverCacheDir);
    } catch (IOException e) {
        logger.info(LogCategories.FILE_DELETE, "Could not delete all files from album cover cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(albumInfoCacheDir);
    } catch (IOException e) {
        logger.info(LogCategories.FILE_DELETE, "Could not delete all files from album info cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(artistImageCacheDir);
    } catch (IOException e) {
        logger.info(LogCategories.FILE_DELETE, "Could not delete all files from artist image cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(artistInfoCacheDir);
    } catch (IOException e) {
        logger.info(LogCategories.FILE_DELETE, "Could not delete all files from artist info cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(artistSimilarCacheDir);
    } catch (IOException e) {
        logger.info(LogCategories.FILE_DELETE, "Could not delete all files from similar artist cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(artistThumbCacheDir);
    } catch (IOException e) {
        logger.info(LogCategories.FILE_DELETE, "Could not delete all files from artist thumbs cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(artistWikiCacheDir);
    } catch (IOException e) {
        logger.info(LogCategories.FILE_DELETE, "Could not delete all files from artist wiki cache");
        exception = true;
    }
    return exception;
}

From source file:edu.uci.ics.pregelix.example.dataload.AsterixDataLoadTest.java

public void setUp(String storePath) throws Exception {
    ClusterConfig.setStorePath(storePath);
    ClusterConfig.setClusterPropertiesPath(PATH_TO_CLUSTER_PROPERTIES);
    ClusterConfig.clearConnection();//from w  w w.ja  va 2  s .com
    cleanupStores();
    PregelixHyracksIntegrationUtil.init();
    LOGGER.info("Hyracks mini-cluster started");
    FileUtils.forceMkdir(new File(ACTUAL_RESULT_DIR));
    FileUtils.cleanDirectory(new File(ACTUAL_RESULT_DIR));

    IOptimizer dynamicOptimizer = new NoOpOptimizer();
    giraphTestJobGen = new JobGenOuterJoin(job, dynamicOptimizer);
}

From source file:com.seleniumtests.ut.util.squashta.TestTaFolderStructureGenerator.java

/**
 * folder structure generation with java file present in source. We check that it's taken
 * @throws IOException/*from w  w w.  j a v  a  2  s . c  o m*/
 */
@Test(groups = { "squash" })
public void testGenerateStructureWithExistingJava() throws IOException {
    File tmpFolder = Paths.get(SeleniumTestsContextManager.getDataPath(), "tmp").toFile();
    File javaFile = Paths
            .get(tmpFolder.getPath(), "src", "squashTA", "resources", "junit", "java", "SeleniumRobotTest.java")
            .toFile();
    FileUtils.writeStringToFile(javaFile, "javaExist");

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

From source file:functionaltests.dataspaces.TestDataspaceConcurrentTransfer.java

@Before
public void setUp() throws Exception {
    Scheduler sched = schedulerHelper.getSchedulerInterface();
    String globalURI = sched.getGlobalSpaceURIs().get(0);
    assertTrue(globalURI.startsWith("file:"));
    log("Global Space URI is " + globalURI);
    globalSpaceFile = new File(new URI(globalURI));

    FileUtils.cleanDirectory(globalSpaceFile);
}

From source file:ext.services.lastfm.LastFmCache.java

/**
 * Clears the cache./*from   w ww.  j av  a 2  s  .c  o m*/
 * 
 * @return If an IOException occured during clearing
 */
public synchronized boolean clearCache() {
    boolean exception = false;
    try {
        FileUtils.cleanDirectory(getAlbumCoverCacheDir());
    } catch (IOException e) {
        Log.info("Could not delete all files from album cover cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(getAlbumInfoCacheDir());
    } catch (IOException e) {
        Log.info("Could not delete all files from album info cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(getArtistImageCacheDir());
    } catch (IOException e) {
        Log.info("Could not delete all files from artist image cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(getAlbumListCacheDir());
    } catch (IOException e) {
        Log.info("Could not delete all files from album list cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(getArtistSimilarCacheDir());
    } catch (IOException e) {
        Log.info("Could not delete all files from similar artist cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(getArtistThumbsCacheDir());
    } catch (IOException e) {
        Log.info("Could not delete all files from artist thumbs cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(getArtistWikiCacheDir());
    } catch (IOException e) {
        Log.info("Could not delete all files from artist wiki cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(getArtistInfoCacheDir());
    } catch (IOException e) {
        Log.info("Could not delete all files from artist info cache");
        exception = true;
    }
    try {
        FileUtils.cleanDirectory(getSubmissionDataDir());
    } catch (IOException e) {
        Log.info("Could not delete all files from submission data cache");
        exception = true;
    }
    return exception;
}

From source file:edu.uci.ics.pregelix.example.asterixdb.ConnectorTest.java

private static void setUpPregelix() throws Exception {
    ClusterConfig.setStorePath(PATH_TO_CLUSTER_STORE);
    ClusterConfig.setClusterPropertiesPath(PATH_TO_CLUSTER_PROPERTIES);
    cleanupStores();//from   w w w .j a  v  a  2s.  com
    PregelixHyracksIntegrationUtil.init();

    System.setProperty(GlobalConfig.CONFIG_FILE_PROPERTY, TEST_CONFIG_FILE_NAME);

    LOGGER.info("Hyracks mini-cluster started");
    FileUtils.forceMkdir(new File(ACTUAL_RESULT_DIR));
    FileUtils.cleanDirectory(new File(ACTUAL_RESULT_DIR));
    startHDFS();
}

From source file:hydrograph.ui.graph.debug.service.PurgeViewDataFiles.java

/**
 * The Function will remove View Execution History Csv Files.
 */// w w  w. ja v  a2s .  co m
private void purgeViewDataCsvFiles() {
    try {
        FileUtils.cleanDirectory(
                new File(Platform.getInstallLocation().getURL().getPath() + JOB_TRACKING_CSV_FILE_PATH));
        logger.debug("Removed ViewExecutionHistory csv file:::");
    } catch (IOException exception) {
        logger.error("Failed to remove ViewExecutionHistory csv file.", exception);
    }
}