Example usage for java.io File setLastModified

List of usage examples for java.io File setLastModified

Introduction

In this page you can find the example usage for java.io File setLastModified.

Prototype

public boolean setLastModified(long time) 

Source Link

Document

Sets the last-modified time of the file or directory named by this abstract pathname.

Usage

From source file:org.artifactory.repo.db.importexport.DbExportBase.java

protected void writeFile(File metadataFile, String xmlData, long lastModified) {
    if (StringUtils.isBlank(xmlData)) {
        return;/*from   w  w w. j a  va 2 s .  co m*/
    }
    try {
        FileUtils.writeStringToFile(metadataFile, xmlData, Charsets.UTF_8.name());
        metadataFile.setLastModified(lastModified);
    } catch (Exception e) {
        status.error("Failed to export metadata of '" + metadataFile.getPath() + "' + to '"
                + metadataFile.getAbsolutePath(), e, log);
        FileUtils.deleteQuietly(metadataFile);
    }
}

From source file:de.crowdcode.movmvn.core.Unzipper.java

/**
 * Unzip a file./*from  ww  w  .j  a  v  a 2s .  c om*/
 * 
 * @param archiveFile
 *            to be unzipped
 * @param outPath
 *            the place to put the result
 * @throws IOException
 *             exception
 * @throws ZipException
 *             exception
 */
public void unzipFileToDir(final File archiveFile, final File outPath) throws IOException, ZipException {
    ZipFile zipFile = new ZipFile(archiveFile);
    Enumeration<ZipArchiveEntry> e = zipFile.getEntries();
    while (e.hasMoreElements()) {
        ZipArchiveEntry entry = e.nextElement();
        File file = new File(outPath, entry.getName());
        if (entry.isDirectory()) {
            FileUtils.forceMkdir(file);
        } else {
            InputStream is = zipFile.getInputStream(entry);
            FileOutputStream os = FileUtils.openOutputStream(file);
            try {
                IOUtils.copy(is, os);
            } finally {
                os.close();
                is.close();
            }
            file.setLastModified(entry.getTime());
        }
    }
}

From source file:org.apache.archiva.repository.scanner.RepositoryScannerTest.java

private ManagedRepository createSimpleRepository() throws IOException, ParseException {
    File srcDir = Paths.get(System.getProperty("basedir"), "src/test/repositories/simple-repository").toFile();

    File repoDir = Paths.get(System.getProperty("basedir"), "target/test-repos/simple-repository").toFile();

    FileUtils.deleteDirectory(repoDir);/*from   ww  w . ja  va2s.c  o m*/

    FileUtils.copyDirectory(srcDir, repoDir);

    File repoFile = new File(repoDir,
            "groupId/snapshot-artifact/1.0-alpha-1-SNAPSHOT/snapshot-artifact-1.0-alpha-1-20050611.202024-1.pom");
    repoFile.setLastModified(getTimestampAsMillis("20050611.202024"));

    assertTrue("Simple Test Repository should exist.", repoDir.exists() && repoDir.isDirectory());

    return createRepository("testSimpleRepo", "Test Simple Repository", repoDir);
}

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

/**
 * Stores and digests a temporary FileBlob.
 *//*  w  ww  .  j  a  v a 2 s .  co  m*/
protected String storeAndDigest(FileBlob blob) throws IOException {
    String digest;
    try (InputStream in = blob.getStream()) {
        digest = storeAndDigest(in, NullOutputStream.NULL_OUTPUT_STREAM);
    }
    File digestFile = getFileForDigest(digest, true);
    if (digestFile.exists()) {
        // The file with the proper digest is already there so don't do anything. This is to avoid
        // "Stale NFS File Handle" problems which would occur if we tried to overwrite it anyway.
        // Note that this doesn't try to protect from the case where two identical files are uploaded
        // at the same time.
        // Update date for the GC.
        digestFile.setLastModified(blob.getFile().lastModified());
    } else {
        blob.moveTo(digestFile);
    }
    return digest;
}

From source file:com.funambol.server.cleanup.ClientLogCleanUpAgentTest.java

public void testInternalRun_ArchivationRequiredArchive_LogWithOldTmp() throws Throwable {

    String userBDir = LOGS_DIR + File.separator + "user-b" + File.separator + "uploadinprogress.tmp";
    File tmpFile = new File(userBDir);
    IOTools.writeFile("upload in progress..", tmpFile);
    assertTrue("Unable to set last modified time",
            tmpFile.setLastModified(System.currentTimeMillis() - 4000000));

    ClientLogCleanUpAgent instance = new ClientLogCleanUpAgent(LOGS_DIR, ARCHIVE_DIR, activationThreshold,
            maxNumberOfArchivedFiles, numberOfArchivedFilesToDelete, timeToRest, lockName);

    PrivateAccessor.invoke(instance, "internalRun", null, null);

    File f = new File(ARCHIVE_DIR);
    assertTrue("Archive dir does not exist", f.exists());
    String[] childs = f.list();//from   w ww . j  av  a 2 s.com
    assertTrue("Archive dir contains more children", childs.length == 1);
    assertTrue("Archive dir contains only lock file", childs[0].endsWith(".zip"));

    File log = new File(LOGS_DIR);
    assertTrue("Log dir does not exist", log.exists());
    String[] logChilds = log.list();
    assertTrue("Log dir contains more children", logChilds.length == 1);
    assertFalse("The tmp file does not exist anymore", tmpFile.exists());
    assertTrue("Log dir contains only lock file", logChilds[0].endsWith(".lck"));
}

From source file:com.openedit.util.FileUtils.java

/**
 * DOCME/* w w  w .  j a  v a  2  s. co  m*/
 * 
 * @param src
 *            DOCME
 * @param dst
 *            DOCME
 * @param buffer
 *            DOCME
 * 
 * @throws IOException
 *             DOCME
 */
public void fileCopy(File src, File dst) throws IOException {
    fieldFiller.fill(src, dst);

    // Preserve the modification date of the original file.
    dst.setLastModified(src.lastModified());
}

From source file:net.firejack.platform.core.store.registry.FileStore.java

@Override
public void upload(InputStream stream, String... path) throws IOException {
    FileUtils.checkPath(base, path);/*  w w  w .j av  a2s .  co m*/
    File file = FileUtils.create(base, path);
    FileUtils.forceMkdir(file.getParentFile());

    FileOutputStream outputStream = new FileOutputStream(file);
    IOUtils.copy(stream, outputStream);
    IOUtils.closeQuietly(outputStream);

    String name = file.getName();
    String ttl = name.substring(name.indexOf(".") + 1);
    if (StringUtils.isNumeric(ttl) && file.setLastModified(Long.parseLong(ttl))) {
        logger.debug("Change ttl:" + ttl + " for file: " + file.getAbsolutePath());
    }
}

From source file:org.apache.hadoop.gateway.services.topology.DefaultTopologyServiceTest.java

private File createFile(File parent, String name, String resource, long timestamp) throws IOException {
    File file = new File(parent, name);
    if (!file.exists()) {
        FileUtils.touch(file);/*from  ww  w. j av a 2s .  co  m*/
    }
    InputStream input = ClassLoader.getSystemResourceAsStream(resource);
    OutputStream output = FileUtils.openOutputStream(file);
    IOUtils.copy(input, output);
    //KNOX-685: output.flush();
    input.close();
    output.close();
    file.setLastModified(timestamp);
    assertTrue("Failed to create test file " + file.getAbsolutePath(), file.exists());
    assertTrue("Failed to populate test file " + file.getAbsolutePath(), file.length() > 0);

    return file;
}

From source file:org.springframework.integration.sftp.outbound.SftpServerOutboundTests.java

private long setModifiedOnSource1() {
    File firstRemote = new File(getSourceRemoteDirectory(), " sftpSource1.txt");
    firstRemote.setLastModified(System.currentTimeMillis() - 1_000_000);
    long modified = firstRemote.lastModified();
    assertTrue(modified > 0);/*from   ww w.  ja v a2s  .  c  o  m*/
    return modified;
}

From source file:org.sonar.ce.log.CeLoggingTest.java

@Test
public void delete_oldest_files_of_same_directory_to_keep_only_max_allowed_files() throws IOException {
    for (int i = 1; i <= 5; i++) {
        File file = new File(dataDir, format("U%d.log", i));
        FileUtils.touch(file);/*from   ww  w . ja  v  a  2s.  c  o m*/
        // see javadoc: "all platforms support file-modification times to the nearest second,
        // but some provide more precision" --> increment by second, not by millisecond
        file.setLastModified(1_450_000_000_000L + i * 1000);
    }
    assertThat(dataDir.listFiles()).hasSize(5);

    // keep 3 files in each dir
    CeLogging underTest = new CeLogging(newSettings(dataDir, 3));
    underTest.purgeDir(dataDir);

    assertThat(dataDir.listFiles()).hasSize(3);
    assertThat(dataDir.listFiles()).extracting("name").containsOnly("U3.log", "U4.log", "U5.log");
}