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:hydrograph.ui.graph.debug.service.PurgeViewDataFiles.java

/**
 * The Function will remove View Execution History Log Files. 
  *//* w  w  w.  j  ava  2  s.c  o m*/
private void purgeViewExecutionHistoryLogs() {
    try {
        FileUtils.cleanDirectory(new File(XMLConfigUtil.CONFIG_FILES_PATH + JOB_TRACKING_LOG_PATH));
        logger.debug("Removed ViewExecutionHistory logs file:::");
    } catch (IOException exception) {
        logger.error("Failed to remove ViewExecutionHistory logs file.", exception);
    }
}

From source file:hoot.services.controllers.ingest.CustomScriptResourceTest.java

@After
public void afterTest() throws IOException {
    File scriptFolder = new File(res.scriptFolder);
    if (scriptFolder.exists()) {
        FileUtils.cleanDirectory(scriptFolder);
    }//from ww  w .  j  a  v  a 2s. co  m
}

From source file:com.xpn.xwiki.plugin.graphviz.GraphVizPlugin.java

/**
 * {@inheritDoc}/* ww w .  j av  a2s. c  o m*/
 * 
 * @see XWikiPluginInterface#flushCache(XWikiContext)
 */
@Override
public void flushCache() {
    try {
        FileUtils.cleanDirectory(this.tempDir);
    } catch (Exception e) {
        // Public APIs shouldn't throw errors; this shouldn't happen anyway
    }
}

From source file:com.ibm.liberty.starter.api.v1.LibertyFileUploader.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String tech = request.getParameter(PARAMETER_TECH);
    String workspaceId = request.getParameter(PARAMETER_WORKSPACE); //specify the unique workspace directory to upload the file(s) to.   
    Collection<Part> filePartCollection = request.getParts();

    String serverHostPort = request.getRequestURL().toString().replace(request.getRequestURI(), "");
    int schemeLength = request.getScheme().toString().length();
    String internalHostPort = "http" + serverHostPort.substring(schemeLength);
    log.log(Level.FINER, "serverHostPort : " + serverHostPort);
    final ServiceConnector serviceConnector = new ServiceConnector(serverHostPort, internalHostPort);
    HashMap<Part, String> fileNames = new HashMap<Part, String>();
    if (!isValidRequest(request, response, tech, workspaceId, filePartCollection, serviceConnector,
            fileNames)) {//from  www  . j  a  v  a  2  s . co  m
        return;
    }

    Service techService = serviceConnector.getServiceObjectFromId(tech);
    String techDirPath = StarterUtil.getWorkspaceDir(workspaceId) + "/" + techService.getId();
    File techDir = new File(techDirPath);
    if (techDir.exists() && techDir.isDirectory()
            && "true".equalsIgnoreCase(request.getParameter(PARAMETER_CLEANUP))) {
        FileUtils.cleanDirectory(techDir);
        log.log(Level.FINER, "Cleaned up tech workspace directory : " + techDirPath);
    }

    for (Part filePart : filePartCollection) {
        if (!techDir.exists()) {
            FileUtils.forceMkdir(techDir);
            log.log(Level.FINER, "Created tech directory :" + techDirPath);
        }

        String filePath = techDirPath + "/" + fileNames.get(filePart);
        log.log(Level.FINER, "File path : " + filePath);
        File uploadedFile = new File(filePath);

        Files.copy(filePart.getInputStream(), uploadedFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        log.log(Level.FINE, "Copied file to " + filePath);
    }

    if ("true".equalsIgnoreCase(request.getParameter(PARAMETER_PROCESS))) {
        // Process uploaded file(s)
        String processResult = serviceConnector.processUploadedFiles(techService, techDirPath);
        if (!processResult.equalsIgnoreCase("success")) {
            log.log(Level.INFO,
                    "Error processing the files uploaded to " + techDirPath + " : Result=" + processResult);
            response.sendError(500, processResult);
            return;
        }
        log.log(Level.FINE, "Processed the files uploaded to " + techDirPath);
    }

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("success");
    out.close();
}

From source file:edu.uci.ics.hyracks.hdfs.dataflow.DataflowTest.java

private void cleanupStores() throws IOException {
    FileUtils.forceMkdir(new File("teststore"));
    FileUtils.forceMkdir(new File("build"));
    FileUtils.cleanDirectory(new File("teststore"));
    FileUtils.cleanDirectory(new File("build"));
}

From source file:com.adaptris.core.services.dynamic.DynamicServiceLocatorTest.java

@Override
protected void tearDown() throws Exception {
    FileUtils.cleanDirectory(tempDir);
    FileUtils.deleteQuietly(tempDir);
}

From source file:edu.uci.ics.hyracks.hdfs2.dataflow.DataflowTest.java

@Override
public void setUp() throws Exception {
    conf = new Job();
    cleanupStores();//from  www .j  av a2 s . co m
    HyracksUtils.init();
    FileUtils.forceMkdir(new File(ACTUAL_RESULT_DIR));
    FileUtils.cleanDirectory(new File(ACTUAL_RESULT_DIR));
    startHDFS();
}

From source file:com.zotoh.core.util.FileUte.java

/**
 * @param dir/*w ww  . j  av  a  2 s  . c o m*/
 * @return
 * @throws IOException
 */
public static void purgeDirFiles(File dir) throws IOException {
    if (dir != null) {
        FileUtils.cleanDirectory(dir);
    }
}

From source file:com.kelveden.rastajax.cli.Runner.java

private static File ensureWorkingDirectory() throws CliExecutionException {

    final File tempFolder = new File(FileUtils.getTempDirectory(), "rastajax-explode");

    try {/*from ww  w  . j  av a  2s  .c o  m*/
        FileUtils.forceMkdir(tempFolder);
        FileUtils.cleanDirectory(tempFolder);

    } catch (final IOException e) {
        throw new CliExecutionException("Failed to ensure presence of working folder.", e);
    }

    return tempFolder;
}

From source file:com.thoughtworks.go.plugin.infra.commons.PluginsListTest.java

@Test
public void shouldHaveThePluginsListedInSortedOrderBasedOnNameInPluginsJSON() throws Exception {
    FileUtils.cleanDirectory(externalPluginsDir);
    FileUtil.createFilesByPath(externalPluginsDir, "foo", "bar", "baz", "ano");
    pluginsList.update();/*from   w w  w .  j a  va 2  s .co m*/

    String pluginsJSON = pluginsList.getPluginsJSON();

    PluginsList deserialized = JsonHelper.fromJson(pluginsJSON, PluginsList.class);
    PluginsList.PluginEntries externalPlugins = (PluginsList.PluginEntries) ReflectionUtil
            .getField(deserialized, "external");

    assertThat(externalPlugins.size(), is(4));
    assertThat(externalPlugins.get(0).getName(), is("ano"));
    assertThat(externalPlugins.get(1).getName(), is("bar"));
    assertThat(externalPlugins.get(2).getName(), is("baz"));
    assertThat(externalPlugins.get(3).getName(), is("foo"));
}