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:com.jaeksoft.searchlib.config.ConfigFileRotation.java

public PrintWriter getTempPrintWriter(String encoding) throws IOException {
    lock.rl.lock();//w w w .  j a v a 2  s .  c  o  m
    try {
        if (tempPrintWriter != null)
            return tempPrintWriter;
        if (!tempFile.exists())
            FileUtils.touch(tempFile);
        tempPrintWriter = new PrintWriter(tempFile, encoding);
        return tempPrintWriter;
    } finally {
        lock.rl.unlock();
    }
}

From source file:edu.umn.msi.tropix.common.io.FileUtilsImpl.java

public void touch(final File file) {
    try {/* www.ja v  a2s  . co  m*/
        FileUtils.touch(file);
    } catch (final IOException e) {
        throw new IORuntimeException(e);
    }
}

From source file:com.piketec.jenkins.plugins.tpt.publisher.InvisibleActionHostingHtml.java

/**
 * This method is called when an InvisibleActionHostingHtml object is created. It displays the
 * "index.html"/*w w w  .j  a va2s .c om*/
 * 
 * @param req
 *          The request
 * @param rsp
 *          The response
 * @throws IOException
 *           If an IO error occures
 * @throws ServletException
 *           If the response could not be generated
 */
public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {

    File f = new File(path() + File.separator + "index.html");
    FileUtils.touch(f); // refresh the index if security changed
    // this displays the "index.html" in the given path
    DirectoryBrowserSupport dbs = new DirectoryBrowserSupport(this, new FilePath(new File(path())),
            "TPT Report", "clipboard.png", false);
    if (req.getRestOfPath().equals("")) {
        throw HttpResponses.forwardToView(this, "index.jelly");
    }
    dbs.generateResponse(req, rsp, this);
}

From source file:com.thoughtworks.go.agent.launcher.LockfileTest.java

@Test
public void shouldNotDeleteLockFileIfTryLockHasFailed() throws IOException {
    FileUtils.touch(LOCK_FILE);
    Lockfile lockfile = new Lockfile(LOCK_FILE);
    assertThat(lockfile.tryLock(), is(false));
    lockfile.delete();/*from w  w w.j  a va2s.  c  om*/
    assertThat(LOCK_FILE.exists(), is(true));
}

From source file:com.ning.metrics.collector.hadoop.processing.TestHadoopWriterFactory.java

private void testProcessLeftBelowFilesTooSoon() throws Exception {
    final HadoopWriterFactory factory = new NoWriteHadoopWriterFactory(null, config);

    FileUtils.touch(new File(lockDirectory.getPath() + "/some_file_which_should_be_sent_1"));
    FileUtils.touch(new File(lockDirectory.getPath() + "/some_file_which_should_be_sent_2"));
    FileUtils.touch(new File(quarantineDirectory.getPath() + "/some_other_file_which_should_be_sent"));

    Assert.assertEquals(FileUtils/*from  w  w  w.j a va2 s. c  o  m*/
            .listFiles(spoolDirectory, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter())
            .size(), 3);
    Assert.assertTrue(spoolDirectory.exists());
    Assert.assertTrue(tmpDirectory.exists());
    Assert.assertTrue(lockDirectory.exists());
    Assert.assertTrue(quarantineDirectory.exists());

    // No sleep!
    factory.processLeftBelowFiles();

    // No file should have been sent
    Assert.assertEquals(FileUtils
            .listFiles(spoolDirectory, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter())
            .size(), 3);
    Assert.assertTrue(spoolDirectory.exists());
    Assert.assertTrue(tmpDirectory.exists());
    Assert.assertTrue(lockDirectory.exists());
    Assert.assertTrue(quarantineDirectory.exists());

    // We could even test the mapping in HDFS here (with the keys)
    Assert.assertEquals(hdfs.values().size(), 0);
}

From source file:com.izforge.izpack.event.BSFUninstallerListenerTest.java

/**
 * Tests the {@link BSFUninstallerListener}.
 *
 * @param actions the uninstallation actions
 * @param suffix  the file name suffix//from w ww . j av  a  2  s.c  o m
 * @throws IOException for any I/O error
 */
public void checkListener(List<BSFAction> actions, String suffix) throws IOException {
    UninstallerListener listener = createListener(actions);
    listener.initialise();

    File file1 = new File(installDir, "file1.txt");
    File file2 = new File(installDir, "file2.txt");
    List<File> files = Arrays.asList(file1, file2);
    for (File file : files) {
        FileUtils.touch(file);
    }

    System.setProperty("TEST_INSTALL_PATH", installDir.getPath());
    // hack to pass additional parameters to script. TODO

    assertFileNotExists(installDir, "beforedeletion" + suffix);
    listener.beforeDelete(files);
    assertFileExists(installDir, "beforedeletion" + suffix);

    assertFileNotExists(installDir, "beforedelete" + suffix);
    listener.beforeDelete(file1);
    assertFileExists(installDir, "beforedelete" + suffix);

    assertFileNotExists(installDir, "afterdelete" + suffix);
    listener.afterDelete(file1);
    assertFileExists(installDir, "afterdelete" + suffix);

    assertFileNotExists(installDir, "afterdeletion" + suffix);
    listener.afterDelete(files, Mockito.mock(ProgressListener.class));
    assertFileExists(installDir, "afterdeletion" + suffix);
}

From source file:it.anyplace.sync.core.cache.FileBlockCache.java

private @Nullable byte[] pullFile(String code, boolean shouldCheck) {

    final File file = new File(dir, code);
    if (file.exists()) {
        try {/* www.  j a  v a 2  s .c  om*/
            byte[] data = FileUtils.readFileToByteArray(file);
            if (shouldCheck) {
                String cachedDataCode = BaseEncoding.base16()
                        .encode(Hashing.sha256().hashBytes(data).asBytes());
                checkArgument(equal(code, cachedDataCode), "cached data code %s does not match code %s",
                        cachedDataCode, code);
            }
            writerThread.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        FileUtils.touch(file);
                    } catch (IOException ex) {
                        logger.warn("unable to 'touch' file {}", file);
                        logger.warn("unable to 'touch' file", ex);
                    }
                }

            });
            logger.debug("read block {} from cache file {}", code, file);
            return data;
        } catch (Exception ex) {
            logger.warn("error reading block from cache", ex);
            FileUtils.deleteQuietly(file);
        }
    }
    return null;
}

From source file:net.sf.taverna.raven.plugins.ui.CheckForUpdatesDialog.java

protected void okPressed() {
    try {//from ww  w .  j  a  v a  2s . c om
        FileUtils.touch(CheckForUpdatesStartupHook.lastUpdateCheckFile);
    } catch (IOException ioex) {
        logger.error("Failed to touch the 'Last update check' file for Taverna updates.", ioex);
    }
    closeDialog();
}

From source file:com.qcadoo.plugin.internal.filemanager.PluginFileManagerTest.java

@Test
public void shouldUninstallNotTemporaryPluginFile() throws Exception {
    // given//  w ww.j a v a  2s  . c o  m
    File pluginFile = new File(destination, "uninstallpluginname.jar");
    FileUtils.touch(pluginFile);

    // when
    defaultPluginFileManager.uninstallPlugin("uninstallpluginname.jar");

    // then
    assertFalse(pluginFile.exists());
}

From source file:com.funambol.server.config.ConfigurationTest.java

@Override
protected void setUp() throws Exception {
    File initialPlugin = new File(funambolHome,
            "com/funambol/server/config/Configuration/plugin/initial-plugins");

    FileUtils.forceMkdir(runtimePluginDir);
    FileUtils.cleanDirectory(runtimePluginDir);
    FileUtils.copyDirectory(initialPlugin, runtimePluginDir, new WildcardFileFilter("*.xml"));

    ////www  .  ja v a  2 s  . c o m
    // This is required since if the plugin xml files used in the tests are 
    // downloaded from SVN repository, they have the same timestamp so the changes
    // are not correctly detected by the DirectoryMonitor. In this way we are sure
    // the timestamp is different (touch uses the current timestamp and of course the
    // files - in src/test/data/com/funambol/server/config/Configuration/pluging/test-1 -
    // are downloaded previously)
    //
    File[] files = runtimePluginDir.listFiles();
    for (File file : files) {
        FileUtils.touch(file);
    }

    Configuration.getConfiguration();
}