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.ojbc.connectors.custodyreleasereporting.CamelContextTest.java

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

    custodyReleaseReportingServiceMockEndpoint.expectedMessageCount(1);

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

    File inputDirectory = new File(inputDirectoryString);

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

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

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

    Thread.sleep(5000);

    custodyReleaseReportingServiceMockEndpoint.assertIsSatisfied();

    Exchange ex = custodyReleaseReportingServiceMockEndpoint.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.custodystatuschangereporting.CamelContextTest.java

@Test
public void contextStartup() throws Exception {
    assertTrue(true);// w w  w.  j  a v a2s. com

    custodyStatusChangeReportingServiceMockEndpoint.expectedMessageCount(1);

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

    File inputDirectory = new File(inputDirectoryString);

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

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

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

    Thread.sleep(5000);

    custodyStatusChangeReportingServiceMockEndpoint.assertIsSatisfied();

    Exchange ex = custodyStatusChangeReportingServiceMockEndpoint.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.dispositionreporting.CamelContextTest.java

@Test
public void contextStartup() throws Exception {
    assertTrue(true);//from  w  w w  .j a  va2s  .  c  o m

    dispositionReportingServiceMockEndpoint.expectedMessageCount(1);

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

    File inputDirectory = new File(inputDirectoryString);

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

    File inputFile = new File("src/test/resources/xmlInstances/Disposition_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);

    dispositionReportingServiceMockEndpoint.assertIsSatisfied();

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

}

From source file:org.ojbc.incidentreporting.tests.IncidentReportingIntegrationTest.java

@Test
public void testIncidentReportFlow() throws Exception {

    //Retrieve camel contexts to get properties from bundle
    incidentReportingConnectorCamelContext = getOsgiService(CamelContext.class,
            "(camel.context.name=incident-reporting-service-connector)", 40000);

    //Upgraded to Java 8, comment out for now
    //ndexSubmissionServiceCamelContext = getOsgiService(CamelContext.class, "(camel.context.name=ndex-submission-service-intermediary)", 40000);

    assertNotNull(incidentReportingConnectorCamelContext);

    //Upgraded to Java 8, comment out for now
    //assertNotNull(ndexSubmissionServiceCamelContext);

    //Get input directory by resolving property
    String inputDirectoryString = incidentReportingConnectorCamelContext
            .resolvePropertyPlaceholders("{{incidentChargeReporting.ConnectorFileDirectory}}") + "/input";
    log.info("Connector input directory:" + inputDirectoryString);

    //Upgraded to Java 8, comment out for now
    //Get intermediary output directory, due to Camel bug, it is retrieved by endpoint
    //Endpoint ndexSuccessEndpoint = ndexSubmissionServiceCamelContext.getEndpoint("ndexSubmissionSuccessDir");
    //assertNotNull(ndexSuccessEndpoint);

    //log.info("NDEx output directory:"+ ndexSuccessEndpoint.getEndpointUri());

    //String ndexSuccessEndpointDirectoryString = StringUtils.substringAfter(ndexSuccessEndpoint.getEndpointUri(), "file:///");

    //Clean the input directory up for a clean test
    File inputDirectory = new File(inputDirectoryString);

    if (inputDirectory.exists()) {
        FileUtils.cleanDirectory(inputDirectory);
    }//from   w w  w  .j a  v  a 2s .  com

    //Clean the ndex directory up for a clean test
    //File ndexDirectory = new File(ndexSuccessEndpointDirectoryString);

    //if (ndexDirectory.exists())
    //{   
    //   FileUtils.cleanDirectory(ndexDirectory);
    //}

    DateTime now = new DateTime();

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

    //Kick off the process by copying the incident report to the input directory (reportable to DA is set to false in incident report)
    FileUtils.copyFileToDirectory(inputFile, inputDirectory);

    //Sleep while processing happens
    Thread.sleep(15000);

    //File ndexDirectoryForToday = new File(ndexSuccessEndpointDirectoryString + "/" +  now.toString("yyyyMMdd") );

    //Assert that we get exactly one file in the ndex 'success' directory and then delete it
    //String[] extensions = {"xml"};
    //Collection<File> files = FileUtils.listFiles(ndexDirectoryForToday, extensions, true);

    //assertEquals(1, files.size());

    //File theNdexResponseFile = files.iterator().next();

    //Confirm ndex file name is correct in 'success' directory
    //assertTrue(theNdexResponseFile.getName().startsWith("INCIDENT_14BU000056"));
    //assertTrue(theNdexResponseFile.getName().endsWith(".xml"));

    //TODO: Support Arrest Reporting Service, Charge Referral Service and Notification Broker Service

}

From source file:org.ojbc.intermediaries.dispositionreporting.DispositionReportingServiceTest.java

private File initializeDirectory(String directoryName) throws IOException {
    File inputDirectory = new File(directoryName);

    if (inputDirectory.exists()) {
        FileUtils.cleanDirectory(inputDirectory);
    }/*from   www  . ja  v a  2 s. co  m*/

    return inputDirectory;
}

From source file:org.onehippo.repository.clustering.ClusterTest.java

private static void cleanup() throws IOException {
    final File repo1Dir = new File(repo1Path);
    if (repo1Dir.exists()) {
        FileUtils.cleanDirectory(repo1Dir);
    }//from   w  w  w.  ja va 2  s . com
    final File repo2Dir = new File(repo2Path);
    if (repo2Dir.exists()) {
        FileUtils.cleanDirectory(repo2Dir);
    }
    final File h2Dir = new File(h2Path);
    if (h2Dir.exists()) {
        FileUtils.cleanDirectory(h2Dir);
    }
}

From source file:org.onehippo.repository.xml.ExportImportPackageTest.java

@Test
public void testImportFromFileURLWithResources() throws Exception {
    HippoSession session = (HippoSession) this.session;

    File tempFile = File.createTempFile("test-import-fuwr", ".tmp");
    File tempDir = new File(tempFile.getParentFile(), StringUtils.removeEnd(tempFile.getName(), ".tmp"));
    tempDir.mkdir();/*from www  .j a  va2  s .com*/

    InputStream xmlInput = null;
    InputStream binaryInput;

    try {
        Map<String, File> entryFilesMap = unzipFileTo(session.exportEnhancedSystemViewPackage("/test", true),
                tempDir);
        xmlInput = new FileInputStream(entryFilesMap.get("esv.xml"));
        ContentResourceLoader contentResourceLoader = new FileContentResourceLoader(tempDir);
        session.importEnhancedSystemViewXML("/test", xmlInput, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW,
                ImportReferenceBehavior.IMPORT_REFERENCE_NOT_FOUND_THROW, contentResourceLoader);
        assertTrue(session.nodeExists("/test/test"));
        final Node test = session.getNode("/test/test");
        assertTrue(test.hasProperty("test"));
        binaryInput = test.getProperty("test").getBinary().getStream();
        assertEquals("test", IOUtils.toString(binaryInput));
        binaryInput.close();
    } finally {
        IOUtils.closeQuietly(xmlInput);
        FileUtils.deleteQuietly(tempFile);
        FileUtils.cleanDirectory(tempDir);
    }
}

From source file:org.onexus.resource.manager.internal.providers.ZipProjectProvider.java

@Override
protected void importProject() {

    try {//from w ww.  j  av  a2  s .  c o  m

        byte[] buffer = new byte[1024];
        URL url = new URL(getProjectUrl());
        ZipInputStream zis = new ZipInputStream(url.openStream());
        ZipEntry ze = zis.getNextEntry();

        File projectFolder = getProjectFolder();
        if (!projectFolder.exists()) {
            projectFolder.mkdir();
        } else {
            FileUtils.cleanDirectory(projectFolder);
        }

        while (ze != null) {

            String fileName = ze.getName();
            File newFile = new File(projectFolder, fileName);
            if (ze.isDirectory()) {
                newFile.mkdir();
            } else {
                FileOutputStream fos = new FileOutputStream(newFile);
                int len;
                while ((len = zis.read(buffer)) > 0) {
                    fos.write(buffer, 0, len);
                }
                fos.close();
            }

            ze = zis.getNextEntry();

        }
        zis.close();

    } catch (Exception e) {

        LOGGER.error("Importing project '" + getProjectUrl() + "'", e);
        throw new InvalidParameterException("Invalid Onexus URL project");
    }

    //To change body of implemented methods use File | Settings | File Templates.
}

From source file:org.opencastproject.manager.system.Restart.java

/**
 * Restarts the framework.//  w  w w  . j  a v  a 2  s . c om
 *
 * @throws IOException
 */
public void restart() throws IOException {

    FileUtils.cleanDirectory(new File(PluginManagerConstants.FELIX_CACHE_PATH));

    final Bundle systemBundle = bundleContext.getBundle(0);

    Thread t = new Thread("Stopper") {

        public void run() {
            try {
                Thread.sleep(2000L);
            } catch (InterruptedException ie) {
            }

            // stopping bundle 0 (system bundle) stops the framework
            try {
                if (false) {
                    systemBundle.update();
                } else {
                    systemBundle.stop();
                }
            } catch (BundleException be) {
                logger.error("Restarting Matterhorn failed.");
            }
        }
    };

    t.start();
}

From source file:org.opendaylight.controller.cluster.persistence.LocalSnapshotStoreSpecTest.java

static void cleanSnapshotDir() {
    if (!SNAPSHOT_DIR.exists()) {
        return;//w  w w . ja v  a2s .  co  m
    }

    try {
        FileUtils.cleanDirectory(SNAPSHOT_DIR);
    } catch (IOException e) {
        // Ignore
    }
}