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:net.orpiske.sdm.lib.net.Downloader.java

/**
 * Saves the downloaded file/*from  ww  w .ja v a 2 s. c  om*/
 * @param outputFile the output file
 * @param resource the resource to save
 * @throws IOException if the file is not found or unable to save the file
 */
private static void saveDownload(File outputFile, Resource<InputStream> resource) throws IOException {
    FileOutputStream output = null;

    try {
        output = new FileOutputStream(outputFile);

        copy(resource, output);
        long lastModified = resource.getResourceInfo().getLastModified();
        if (!outputFile.setLastModified(lastModified)) {
            logger.info("Unable to set the last modified date for " + outputFile.getPath());
        }
    } finally {

        IOUtils.closeQuietly(output);
        IOUtils.closeQuietly(resource.getPayload());
    }
}

From source file:org.eclipse.virgo.ide.jdt.internal.core.util.ClasspathUtils.java

/**
 * Adjusts the last modified timestamp on the source root and META-INF directory to reflect the
 * same date as the MANIFEST.MF.//from  w w  w.  ja  v  a2 s  .  com
 * <p>
 * Note: this is a requirement for the dependency resolution.
 */
public static void adjustLastModifiedDate(IJavaProject javaProject, boolean testBundle) {
    File manifest = BundleManifestUtils.locateManifestFile(javaProject, testBundle);
    if (manifest != null && manifest.canRead()) {
        long lastmodified = manifest.lastModified();
        File metaInfFolder = manifest.getParentFile();
        if (metaInfFolder != null
                && metaInfFolder.getName().equals(BundleManifestCorePlugin.MANIFEST_FOLDER_NAME)
                && metaInfFolder.canWrite()) {
            metaInfFolder.setLastModified(lastmodified);
            File srcFolder = metaInfFolder.getParentFile();
            if (srcFolder != null && srcFolder.canWrite()) {
                srcFolder.setLastModified(lastmodified);
            }
        }
    }
}

From source file:org.apache.flink.test.recovery.AbstractProcessFailureRecoveryTest.java

protected static void touchFile(File file) throws IOException {
    if (!file.exists()) {
        new FileOutputStream(file).close();
    }//from  w w w.j a v  a2s.  c om
    if (!file.setLastModified(System.currentTimeMillis())) {
        throw new IOException("Could not touch the file.");
    }
}

From source file:com.sindicetech.siren.solr.facet.TestSirenFacetProcessorFactory.java

@BeforeClass
private static void initManagedSchemaCore() throws Exception {
    /* Create temporary solrHome folder in the target/ folder for this test because it
     * creates the managed-schema file which we don't want in src/main/resources/...
     * and it renames the original schema-*.xml to schema-*.xml.bak - also undesirable.
     * /* w  w w. ja v  a  2s  .  co  m*/
     * The {@link SolrServerTestCase}, extended by UpdateProcessorTestBase, takes care of
     * keeping the schema clean between individual test runs. 
     * 
     * We don't remove the temporary solrHome folder because it will be cleaned later by 
     * mvn clean anyway (and perhaps more reliably, e.g. on Windows, etc.).
     */
    File tempSolrHome = new File("target" + File.separator
            + TestSirenFacetProcessorFactory.class.getSimpleName() + System.currentTimeMillis());

    FileUtils.copyDirectory(new File(SOLR_HOME), tempSolrHome);
    // make the dir easier to find by time, otherwise it would have last modified time of 
    // the original SOLR_HOME
    tempSolrHome.setLastModified(System.currentTimeMillis());

    initCore("solrconfig-facets.xml", "schema-facets.xml", tempSolrHome.getAbsolutePath());
}

From source file:org.apache.jackrabbit.core.data.FileDataStore.java

/**
 * Set the last modified date of a file, if the file is writable.
 *
 * @param file the file//  www .j  a v  a2s.  co m
 * @param time the new last modified date
 * @throws DataStoreException if the file is writable but modifying the date fails
 */
private static void setLastModified(File file, long time) throws DataStoreException {
    if (!file.setLastModified(time)) {
        if (!file.canWrite()) {
            // if we can't write to the file, so garbage collection will also not delete it
            // (read only files or file systems)
            return;
        }
        try {
            // workaround for Windows: if the file is already open for reading
            // (in this or another process), then setting the last modified date
            // doesn't work - see also JCR-2872
            RandomAccessFile r = new RandomAccessFile(file, "rw");
            try {
                r.setLength(r.length());
            } finally {
                r.close();
            }
        } catch (IOException e) {
            throw new DataStoreException("An IO Exception occurred while trying to set the last modified date: "
                    + file.getAbsolutePath(), e);
        }
    }
}

From source file:org.apache.flink.test.recovery.ProcessFailureBatchRecoveryITCase.java

private static void touchFile(File file) throws IOException {
    if (!file.exists()) {
        new FileOutputStream(file).close();
    }/*from   ww  w.  j  a  v  a2 s  . c  o  m*/
    if (!file.setLastModified(System.currentTimeMillis())) {
        throw new IOException("Could not touch the file.");
    }
}

From source file:org.cloudfoundry.client.lib.SampleProjects.java

private static void unpackZip(ZipFile zipFile, File unpackDir) throws IOException {
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        File destination = new File(unpackDir.getAbsolutePath() + "/" + entry.getName());
        if (entry.isDirectory()) {
            destination.mkdirs();//w  w  w .j a  va 2 s . c  o  m
        } else {
            destination.getParentFile().mkdirs();
            FileCopyUtils.copy(zipFile.getInputStream(entry), new FileOutputStream(destination));
        }
        if (entry.getTime() != -1) {
            destination.setLastModified(entry.getTime());
        }
    }
}

From source file:org.fao.geonet.kernel.mef.Importer.java

protected static void saveFile(ServiceContext context, String id, String access, String file, String changeDate,
        InputStream is) throws IOException {
    String dir = Lib.resource.getDir(context, access, id);

    File outFile = new File(dir, file);
    FileOutputStream os = new FileOutputStream(outFile);
    BinaryFile.copy(is, os, false, true);

    outFile.setLastModified(new ISODate(changeDate).getSeconds() * 1000);
}

From source file:ArchiveUtil.java

private static void extractEntry(File entryFile, JarInputStream jis, JarEntry entry, boolean deleteOnExit)
        throws IOException {
    File parent = new File(entryFile.getParent());
    if (!parent.exists())
        parent.mkdirs();// w w w.  j a  v  a2s.  c  o  m
    ResourceUtil.copy(jis, new FileOutputStream(entryFile));
    entryFile.setLastModified(entry.getTime());
    if (deleteOnExit) {
        parent.deleteOnExit();
        entryFile.deleteOnExit();
    }
}

From source file:org.apache.solr.handler.dataimport.AbstractDataImportHandlerTestCase.java

@SuppressForbidden(reason = "Needs currentTimeMillis to set modified time for a file")
public static File createFile(File tmpdir, String name, byte[] content, boolean changeModifiedTime)
        throws IOException {
    File file = new File(tmpdir.getAbsolutePath() + File.separator + name);
    file.deleteOnExit();/*from ww  w  . ja  va2s.  c  om*/
    FileOutputStream f = new FileOutputStream(file);
    f.write(content);
    f.close();
    if (changeModifiedTime)
        file.setLastModified(System.currentTimeMillis() - 3600000);
    return file;
}