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.mobicents.servlet.restcomm.rvd.storage.FsProjectStorage.java

public static void importProjectFromDirectory(File sourceProjectDirectory, String projectName,
        boolean overwrite, WorkspaceStorage storage) throws StorageException {
    try {/*from   w  w  w. j a  v  a  2s . c  o m*/
        createProjectSlot(projectName, storage);
    } catch (ProjectAlreadyExists e) {
        if (!overwrite)
            throw e;
        else {
            File destProjectDirectory = new File(storage.rootPath + File.separator + projectName);
            try {
                FileUtils.cleanDirectory(destProjectDirectory);
                FileUtils.copyDirectory(sourceProjectDirectory, destProjectDirectory);
            } catch (IOException e1) {
                throw new StorageException("Error importing project '" + projectName + "' from directory: "
                        + sourceProjectDirectory);
            }
        }
    }
}

From source file:org.mycontroller.standalone.StartApp.java

private static void cleanUpServices() {
    // clean the services
    // - MQTT client location
    // - MQTT broker location

    try {//  w  w w  .j  ava 2  s . c  om
        File mqttClientDir = new File(AppProperties.getInstance().getMqttClientPersistentStoresLocation());
        if (mqttClientDir.exists()) {
            FileUtils.cleanDirectory(mqttClientDir);
            _logger.debug("MQTT Client persistent store cleared. [{}]", mqttClientDir.getCanonicalFile());
        }
        File mqttBrokerDir = new File(AppProperties.getInstance().getMqttBrokerPersistentStore())
                .getParentFile();
        if (mqttBrokerDir.exists()) {
            FileUtils.cleanDirectory(mqttBrokerDir);
            _logger.debug("MQTT broker persistent store cleared. [{}]", mqttBrokerDir.getCanonicalFile());
        }
    } catch (IOException ex) {
        _logger.error("Exception,", ex);
    }
}

From source file:org.myjerry.mysite.MySite.java

private static void processProject(Project project, File parentFolder, final String exportFolder)
        throws IOException {
    // build up the project processor
    ProjectProcessor processor = new ProjectProcessor(project, parentFolder);
    processor.process();//ww  w.ja v a  2s . c o  m

    List<ProjectFile> files = processor.getProjectFiles();
    if (files == null || files.size() == 0) {
        System.out.println("No files found to be written in project... exiting!");
        return;
    }

    // build up the list of all files that are being written to disk
    List<String> filesWritten = new ArrayList<String>();
    for (ProjectFile file : files) {
        filesWritten.add(file.getPath());
    }

    // start the export process
    File export = new File(exportFolder);
    if (!export.exists()) {
        export.mkdirs();
    } else {
        System.out.println("Export directory already exists... cleaning it up...");
        FileUtils.cleanDirectory(export);
        System.out.println("Done cleaning!");
    }

    Set<String> hyperLinks = new HashSet<String>();
    for (ProjectFile file : files) {
        if (file.isHTML()) {
            HtmlSource source = new HtmlSource(file);
            List<String> links = source.extractAllHyperLinks();

            // check if the link exists in the exported code
            for (String link : links) {
                String linkAsPath = getLinkAsPath(link);
                if (linkAsPath != null) {
                    if (!filesWritten.contains(linkAsPath)) {
                        System.out
                                .println("File " + file.getPath() + " contains an invalid hyperlink: " + link);
                    }
                }
            }

            // add to the main list for export
            hyperLinks.addAll(links);

            // tidy the code
            source.tidyHtml();
        }

        // write the file to disk
        file.writeToDisk(export);
    }

    // check for all hyperlinks in the files
    //      for(String link : hyperLinks) {
    //         System.out.println(link);
    //      }
}

From source file:org.n52.movingcode.runtime.coderepository.LocalVersionedFileRepository.java

/**
 * Remove a package with a given ID from this repository
 * /*  www.  j  av  a  2  s  .com*/
 * @param pid
 * @return
 */
public boolean removePackage(PID pid) {

    // 1. unregister package, so it cannot be found any longer
    // 2. remove directory
    // 3. TODO: care for errors in case something goes wrong to make sure we are
    //    not left in an undefined state 
    unregister(pid);

    File packageDir = new File(packageFolders.get(pid));
    try {
        FileUtils.cleanDirectory(packageDir);
        FileUtils.deleteDirectory(packageDir);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }

    // 4. remove folder from inventory
    packageFolders.remove(pid);

    return true;
}

From source file:org.neo4j.ha.BackupHaIT.java

private void cleanData() throws IOException {
    FileUtils.cleanDirectory(new File(PATH, "neo4j.ha/server1"));
    FileUtils.cleanDirectory(new File(PATH, "neo4j.ha/server2"));
    FileUtils.cleanDirectory(new File(PATH, "neo4j.ha/server3"));
}

From source file:org.nuxeo.ecm.core.blob.binary.LocalBinaryManager.java

@Override
public void close() {
    if (tmpDir != null) {
        try {//from  w  w w  .j  a  v a2s . c om
            FileUtils.cleanDirectory(tmpDir);
        } catch (IOException e) {
            throw new NuxeoException(e);
        }
    }
}

From source file:org.objectpocket.storage.FileStore.java

@Override
public void createBackup() throws IOException {
    // backup current data
    File storeDir = new File(directory);
    if (storeDir.exists() && storeDir.isDirectory()) {
        Set<File> filesToBackup = new HashSet<>();
        File[] files = storeDir.listFiles();
        for (File file : files) {
            String name = file.getName();
            if (!file.isDirectory() && (name.endsWith(FILENAME_SUFFIX) || name.equals(INDEX_FILE_NAME))) {
                filesToBackup.add(file);
            }//from  w  ww.ja v a 2  s . co m
        }
        File backupDir = new File(storeDir.getAbsolutePath() + "/" + ".bak");
        if (backupDir.exists()) {
            FileUtils.cleanDirectory(backupDir);
        } else {
            backupDir.mkdirs();
        }
        for (File file : filesToBackup) {
            FileUtils.copyFileToDirectory(file, backupDir);
        }
    }
}

From source file:org.ojbc.connectors.bookingreporting.CamelContextTest.java

@Test
public void contextStartup() throws Exception {
    assertTrue(true);//from  w w  w.ja v  a  2s .c om

    bookingReportingServiceMockEndpoint.expectedMessageCount(1);

    //Get input directory by resolving property
    String inputDirectoryString = context
            .resolvePropertyPlaceholders("{{bookingReporting.connectorFileDirectory}}") + "/input";
    log.info("Connector input directory:" + inputDirectoryString);
    assertEquals("/tmp/ojb/demo/bookingReporting/connector/input", inputDirectoryString);

    File inputDirectory = new File(inputDirectoryString);

    if (inputDirectory.exists()) {
        FileUtils.cleanDirectory(inputDirectory);
    }

    File inputFile = new File("src/test/resources/xmlInstances/BookingReportJail.xml");
    assertNotNull(inputFile);

    //Kick off the process by copying the process record file to the input directory 
    FileUtils.copyFileToDirectory(inputFile, inputDirectory);

    Thread.sleep(5000);

    bookingReportingServiceMockEndpoint.assertIsSatisfied();

    Exchange ex = bookingReportingServiceMockEndpoint.getExchanges().get(0);
    assertEquals(ex.getIn().getHeader("operationName"), CXF_OPERATION_NAME);
    assertEquals(ex.getIn().getHeader("operationNamespace"), CXF_OPERATION_NAMESPACE);

}

From source file:org.ojbc.connectors.casefilingdecisionreporting.CamelContextTest.java

@Test
public void testCaseFilingDecisionReport() throws Exception {
    assertTrue(true);/*from   ww  w.j av  a2 s  .co  m*/

    caseFilingDecisionReportingServiceMockEndpoint.expectedMessageCount(1);

    //Get input directory by resolving property
    String inputDirectoryString = context
            .resolvePropertyPlaceholders("{{caseFilingDecisionReporting.connectorFileDirectory}}") + "/input";
    log.info("Connector input directory:" + inputDirectoryString);
    assertEquals("/tmp/ojb/demo/caseFilingDecisionReportingService/connector/input", inputDirectoryString);

    File inputDirectory = new File(inputDirectoryString);

    if (inputDirectory.exists()) {
        FileUtils.cleanDirectory(inputDirectory);
    }

    File inputFile = new File(
            "src/test/resources/xmlInstances/caseFilingDecisionReporting/caseFilingDecisionReport.xml");
    assertNotNull(inputFile);

    //Kick off the process by copying the case file decision report to the input directory 
    FileUtils.copyFileToDirectory(inputFile, inputDirectory);

    Thread.sleep(3000);

    caseFilingDecisionReportingServiceMockEndpoint.assertIsSatisfied();

    Exchange ex = caseFilingDecisionReportingServiceMockEndpoint.getExchanges().get(0);
    assertEquals(CXF_OPERATION_NAME, ex.getIn().getHeader("operationName"));
    assertEquals(CXF_OPERATION_NAMESPACE, ex.getIn().getHeader("operationNamespace"));

    caseFilingDecisionReportingServiceMockEndpoint.reset();
    caseFilingDecisionReportingServiceMockEndpoint.expectedMessageCount(1);

    inputFile = new File(
            "src/test/resources/xmlInstances/caseFilingDecisionReporting/caseFilingDecisionReportUpdate.xml");
    assertNotNull(inputFile);

    //Kick off the process by copying the case file decision update report file to the input directory 
    FileUtils.copyFileToDirectory(inputFile, inputDirectory);

    Thread.sleep(3000);

    caseFilingDecisionReportingServiceMockEndpoint.assertIsSatisfied();

    ex = caseFilingDecisionReportingServiceMockEndpoint.getExchanges().get(0);
    assertEquals(CXF_OPERATION_NAME_UPDATE, ex.getIn().getHeader("operationName"));
    assertEquals(CXF_OPERATION_NAMESPACE, ex.getIn().getHeader("operationNamespace"));

}

From source file:org.ojbc.connectors.criminalhistoryconsolidationreporting.CamelContextTest.java

@Test
public void contextStartup() throws Exception {
    assertTrue(true);/*from  w w w.ja v a  2s.  co m*/

    criminalHistoryConsolidationReportingServiceMockEndpoint.expectedMessageCount(1);

    //Get input directory by resolving property
    String inputDirectoryString = context
            .resolvePropertyPlaceholders("{{criminalHistoryConsolidation.ConnectorFileDirectory}}") + "/input";
    log.info("Connector input directory:" + inputDirectoryString);
    assertEquals("/tmp/ojb/demo/criminalHistoryConsolidation/connector/input", inputDirectoryString);

    File inputDirectory = new File(inputDirectoryString);

    if (inputDirectory.exists()) {
        FileUtils.cleanDirectory(inputDirectory);
    }

    File inputFile = new File("src/test/resources/xmlInstances/criminal_history_consolidation_report.xml");
    assertNotNull(inputFile);

    //Kick off the process by copying the process record file to the input directory 
    FileUtils.copyFileToDirectory(inputFile, inputDirectory);

    Thread.sleep(5000);

    criminalHistoryConsolidationReportingServiceMockEndpoint.assertIsSatisfied();

    Exchange ex = criminalHistoryConsolidationReportingServiceMockEndpoint.getExchanges().get(0);
    assertEquals(ex.getIn().getHeader("operationName"), CXF_OPERATION_NAME);
    assertEquals(ex.getIn().getHeader("operationNamespace"), CXF_OPERATION_NAMESPACE);

}