Example usage for org.apache.commons.io FileUtils touch

List of usage examples for org.apache.commons.io FileUtils touch

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils touch.

Prototype

public static void touch(File file) throws IOException 

Source Link

Document

Implements the same behaviour as the "touch" utility on Unix.

Usage

From source file:org.betaconceptframework.astroboa.test.AstroboaTestContext.java

private void touchResource(String resourceRelativePath) throws IOException {
    Resource resource = new ClassPathResource(resourceRelativePath);

    if (resource.exists()) {
        File file = resource.getFile();

        if (file.isFile()) {
            FileUtils.touch(file);
        } else {/*from   ww  w. j a v  a  2s . c  o  m*/
            File[] files = file.listFiles();

            if (files != null && files.length > 0) {
                for (File child : files) {
                    FileUtils.touch(child);
                }
            }
        }
    }

}

From source file:org.betaconceptframework.astroboa.test.engine.AbstractRepositoryTest.java

protected void serializeUsingJCR(CmsEntityType cmsEntity) {

     long start = System.currentTimeMillis();

     String repositoryHomeDir = AstroboaClientContextHolder.getActiveClientContext().getRepositoryContext()
             .getCmsRepository().getRepositoryHomeDirectory();

     File serializationHomeDir = new File(
             repositoryHomeDir + File.separator + CmsConstants.SERIALIZATION_DIR_NAME);

     File zipFile = new File(serializationHomeDir,
             "document" + DateUtils.format(Calendar.getInstance(), "ddMMyyyyHHmmss.sss") + ".zip");

     OutputStream out = null;//from ww  w . j  av a  2  s  . co m
     ZipArchiveOutputStream os = null;

     try {

         if (!zipFile.exists()) {
             FileUtils.touch(zipFile);
         }

         out = new FileOutputStream(zipFile);
         os = (ZipArchiveOutputStream) new ArchiveStreamFactory().createArchiveOutputStream("zip", out);

         os.setFallbackToUTF8(true);

         //Serialize all repository using JCR
         os.putArchiveEntry(new ZipArchiveEntry("document-view.xml"));

         final Session session = getSession();

         switch (cmsEntity) {
         case OBJECT:
             session.exportDocumentView(JcrNodeUtils.getContentObjectRootNode(session).getPath(), os, false,
                     false);
             break;
         case REPOSITORY_USER:
             session.exportDocumentView(JcrNodeUtils.getRepositoryUserRootNode(session).getPath(), os, false,
                     false);
             break;
         case TAXONOMY:
             session.exportDocumentView(JcrNodeUtils.getTaxonomyRootNode(session).getPath(), os, false, false);
             break;
         case ORGANIZATION_SPACE:
             session.exportDocumentView(JcrNodeUtils.getOrganizationSpaceNode(session).getPath(), os, false,
                     false);
             break;
         case REPOSITORY:
             session.exportDocumentView(JcrNodeUtils.getCMSSystemNode(session).getPath(), os, false, false);
             break;

         default:
             break;
         }

         os.closeArchiveEntry();

         os.finish();
         os.close();

     } catch (Exception e) {
         throw new CmsException(e);
     } finally {
         if (out != null) {
             IOUtils.closeQuietly(out);
         }

         if (os != null) {
             IOUtils.closeQuietly(os);
         }
         long serialzationDuration = System.currentTimeMillis() - start;

         logger.debug("Export entities using JCR finished in {} ",
                 DurationFormatUtils.formatDurationHMS(serialzationDuration));
     }
 }

From source file:org.betaconceptframework.astroboa.test.engine.service.RepositoryServiceTest.java

public void testRepositoryConfigurationReloading() throws Exception {

    File configuration = retrieveConfigurationFile();

    FileUtils.touch(configuration);

    Thread.sleep(15000); //Sleep 15 seconds 

    Assert.assertTrue(RepositoryRegistry.INSTANCE.configurationHasChanged(),
            "Configuration file " + configuration.getAbsolutePath() + " was not reloaded. Parent directory "
                    + CmsConstants.ASTROBOA_CONFIGURATION_HOME_DIRECTORY);

    String configurationContent = FileUtils.readFileToString(configuration);

    String currentServerURL = "serverURL=\"http://localhost:8080\"";
    String newServerURL = "serverURL=\"http://newServer:8080\"";

    configurationContent = configurationContent.replaceFirst(currentServerURL, newServerURL);

    FileUtils.writeStringToFile(configuration, configurationContent);

    Thread.sleep(15000); //Sleep 15 seconds

    Assert.assertTrue(RepositoryRegistry.INSTANCE.configurationHasChanged());

    //force registry to reload changes
    repositoryService.getAvailableCmsRepositories();

    Assert.assertEquals(RepositoryRegistry.INSTANCE.getDefaultServerURL(), "http://newServer:8080",
            "Repository Registry has not been updated");

    configurationContent = configurationContent.replaceFirst(newServerURL, currentServerURL);

    FileUtils.writeStringToFile(configuration, configurationContent);

}

From source file:org.codehaus.mojo.castor.GenerateMojoTest.java

private File createTimeStampWithTime(long time) throws IOException {
    File timeStampFolder = new File(TIMESTAMP_DIR);
    File timeStampFile = getTimeStampFile();
    if (!timeStampFolder.exists()) {
        timeStampFolder.mkdirs();//from   w ww  . ja  va 2 s .co  m
    }
    if (!timeStampFile.exists()) {
        FileUtils.touch(timeStampFile);
        timeStampFile.setLastModified(time);
    }
    return timeStampFile;
}

From source file:org.codehaus.mojo.sysdeo.SysdeoMojo.java

protected void forceTomcatNature(File projectDir) {
    try {/*from ww w. j  av  a 2  s .com*/
        File dotProject = new File(projectDir, ".project");
        String content = FileUtils.readFileToString(dotProject, null);
        if (content.indexOf("<nature>com.sysdeo.eclipse.tomcat.tomcatnature</nature>") < 0) {
            getLog().info("Add tomcat nature to the eclipse .project file");
            try {
                Xpp3Dom dom = Xpp3DomBuilder.build(new FileReader(dotProject));
                Xpp3Dom nature = new Xpp3Dom("nature");
                nature.setValue("com.sysdeo.eclipse.tomcat.tomcatnature");
                dom.getChild("natures").addChild(nature);
                FileWriter writer = new FileWriter(dotProject);
                Xpp3DomWriter.write(writer, dom);
                writer.close();
            } catch (Exception e) {
                getLog().warn("Failed to add missing tomcat nature to the eclipse .project file", e);
            }
        }

        // Required to force devloader classpath refresh on POM changes
        File dotClassPath = new File(projectDir, ".classpath");
        FileUtils.touch(dotClassPath);
    } catch (IOException e) {
        getLog().info("Failed to retrieve the Eclipse .project file");
    }
}

From source file:org.codice.ddf.spatial.geocoding.index.IndexInitializer.java

private static void fileProcessingComplete(String resource) {
    String processedIndicator = resource + PROCESSED;
    File processedFile = new File(processedIndicator);
    try {//from ww w.  ja  va2s. c  o  m
        FileUtils.touch(processedFile);
    } catch (IOException e) {
        LOGGER.debug("Unable to create {} to indicate {} processed", processedIndicator, resource, e);
    }
}

From source file:org.craftercms.deployer.impl.TargetServiceImplTest.java

@Test
public void testResolveTargetsYamlModified() throws Exception {
    List<Target> targets = targetService.resolveTargets();

    assertEquals(1, targets.size());//from w ww .  j  ava  2 s. c o m

    Target target1 = targets.get(0);

    Thread.sleep(1000);

    FileUtils.touch(new File(targetsFolder, "foobar-test.yaml"));

    targets = targetService.resolveTargets();

    assertEquals(1, targets.size());

    Target target2 = targets.get(0);

    assertNotEquals(target1.getLoadDate(), target2.getLoadDate());
}

From source file:org.craftercms.deployer.impl.TargetServiceImplTest.java

@Test
public void testResolveTargetsContextModified() throws Exception {
    List<Target> targets = targetService.resolveTargets();

    assertEquals(1, targets.size());//  w  w w  . ja v a  2 s .c  om

    Target target1 = targets.get(0);

    Thread.sleep(1000);

    FileUtils.touch(new File(targetsFolder, "foobar-test-context.xml"));

    targets = targetService.resolveTargets();

    assertEquals(1, targets.size());

    Target target2 = targets.get(0);

    assertNotEquals(target1.getLoadDate(), target2.getLoadDate());
}

From source file:org.cricket.hawkeye.codegen.fetcher.AbstractFetcherMethodImpl.java

private boolean touchFiles(String file) {
    try {//from   ww  w.j a  v  a  2  s.c o m
        FileUtils.touch(new File(file));
    } catch (IOException ex) {
        logger.error("Unable to touch  {" + file + "}", ex);
    }
    return true;
}

From source file:org.dataconservancy.dcs.util.stream.fs.FilesystemStreamSourceTest.java

@Before
public void setUp() throws IOException {
    tmpDir = createTemporaryDirectory();
    for (int i = 0; i < expectedCount; i++) {
        exampleFile = new File(tmpDir, String.valueOf(i));
        FileUtils.touch(exampleFile);
    }//from   ww w .  j  a v a  2s .  co m
}