Example usage for java.io File lastModified

List of usage examples for java.io File lastModified

Introduction

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

Prototype

public long lastModified() 

Source Link

Document

Returns the time that the file denoted by this abstract pathname was last modified.

Usage

From source file:gov.nih.nci.caarray.dataStorage.fileSystem.FilesystemDataStorage.java

/**
 * {@inheritDoc}/*ww  w.  j a v a 2  s.  c o m*/
 */
@Override
public Iterable<StorageMetadata> list() {
    final Set<StorageMetadata> metadatas = Sets.newHashSet();
    final File[] files = baseStorageDir().listFiles(new PatternFilenameFilter(".*\\.unc"));
    if (files != null) {
        for (final File file : files) {
            final StorageMetadata sm = new StorageMetadata();
            sm.setCreationTimestamp(new Date(file.lastModified()));
            sm.setHandle(handleFromFile(file));
            sm.setUncompressedSize(file.length());
            metadatas.add(sm);
        }
    }
    return metadatas;
}

From source file:org.openmrs.web.controller.report.export.RowPerObsDataExportListController.java

/**
 * @see org.springframework.web.servlet.mvc.SimpleFormController#referenceData(javax.servlet.http.HttpServletRequest,
 *      java.lang.Object, org.springframework.validation.Errors)
 *///from ww  w  .j  av a 2  s  .com
@Override
@SuppressWarnings("unchecked")
protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();

    List<AbstractReportObject> reportList = (List<AbstractReportObject>) command;
    Map<AbstractReportObject, Date> generatedDates = new HashMap<AbstractReportObject, Date>();
    Map<AbstractReportObject, String> generatedSizes = new HashMap<AbstractReportObject, String>();

    // add the last modified date of the generated file as reference data
    for (AbstractReportObject report : reportList) {
        File file = DataExportUtil.getGeneratedFile((RowPerObsDataExportReportObject) report);

        if (file.exists()) {
            generatedDates.put(report, new Date(file.lastModified()));

            Long size = file.length(); // returned in bytes
            if (size > 1024 * 1024)
                generatedSizes.put(report, size / (1024 * 1024) + "MB");
            else if (size > 1024)
                generatedSizes.put(report, size / 1024 + "kB");
            else
                generatedSizes.put(report, size + "B");
        }
    }

    map.put("generatedDates", generatedDates);
    map.put("generatedSizes", generatedSizes);

    return map;

}

From source file:org.montanafoodhub.base.get.ItemHub.java

protected HashMap<String, Item> readFromFile(Context context) {
    HashMap<String, Item> myItemMap = new HashMap<String, Item>();
    try {/*from   w  w w  . j a v  a 2 s  .c  o m*/
        // getItem the time the file was last changed here
        File myFile = new File(context.getFilesDir() + "/" + fileName);
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        String lastRefreshTSStr = sdf.format(myFile.lastModified());
        Log.w(HubInit.logTag, "Using file (" + fileName + ") last modified on : " + lastRefreshTSStr);
        lastRefreshTS = sdf.getCalendar();

        // create products from the file here
        InputStream inputStream = context.openFileInput(fileName);
        if (inputStream != null) {
            parseCSV(myItemMap, inputStream);
        }
        inputStream.close();
    } catch (FileNotFoundException e) {
        Log.e(HubInit.logTag, "File  (" + fileName + ") not found: " + e.toString());
    } catch (IOException e) {
        Log.e(HubInit.logTag, "Can not read file  (" + fileName + ") : " + e.toString());
    }
    Log.w(HubInit.logTag, "Number of items loaded: " + myItemMap.size());
    return myItemMap;
}

From source file:com.sun.faban.harness.agent.Download.java

private void download(String src, String name, String dest, String context) throws IOException {
    logger.fine("faban.download = " + context);
    if (context == null)
        return; // We are on the master. Just don't download
    if (!context.endsWith("/")) {
        context += '/';
    }//from www .jav  a2s  .c o  m

    File dir = new File(dest);
    if (dir.exists()) {
        if (!dir.isDirectory()) {
            String msg = dir.getName() + " is not a directory. Download terminated";
            logger.severe(msg);
            throw new IOException(msg);
        }
    } else {
        dir.mkdir();
    }
    dir = new File(dir, name);
    if (dir.exists()) {
        File runIdFile = new File(dir, "META-INF");
        runIdFile = new File(runIdFile, "RunID");
        if (runIdFile.exists() && (System.currentTimeMillis() - runIdFile.lastModified()) <= 60000)
            return; // Recent RunID file means the directory is shared.
                    // Don't download.

        FileHelper.recursiveDelete(dir);
    }
    URL url = new URL(context + src + name + '/');
    downloadDir(url, dir);
}

From source file:FileTable2.java

public void setFileStats(File dir) {
    String files[] = dir.list();/* w ww.j  a  v  a2 s .co  m*/
    data = new Object[files.length][titles.length];

    for (int i = 0; i < files.length; i++) {
        File tmp = new File(files[i]);
        data[i][0] = new Boolean(tmp.isDirectory());
        data[i][1] = tmp.getName();
        data[i][2] = new Boolean(tmp.canRead());
        data[i][3] = new Boolean(tmp.canWrite());
        data[i][4] = new Long(tmp.length());
        data[i][5] = new Date(tmp.lastModified());
    }

    // Just in case anyone's listening...
    fireTableDataChanged();
}

From source file:jenkins.plugins.itemstorage.s3.S3UploadAllCallable.java

/**
 * Upload from slave//from  w  ww  . j  a v a 2s  .co m
 */
@Override
public Integer invoke(final TransferManager transferManager, File base, VirtualChannel channel)
        throws IOException, InterruptedException {
    if (!base.exists())
        return 0;

    final AtomicInteger count = new AtomicInteger(0);
    final Uploads uploads = new Uploads();

    final Map<String, S3ObjectSummary> summaries = lookupExistingCacheEntries(
            transferManager.getAmazonS3Client());

    // Find files to upload that match scan
    scanner.scan(base, new FileVisitor() {
        @Override
        public void visit(File f, String relativePath) throws IOException {
            if (f.isFile()) {
                String key = pathPrefix + "/" + relativePath;

                S3ObjectSummary summary = summaries.get(key);
                if (summary == null || f.lastModified() > summary.getLastModified().getTime()) {
                    final ObjectMetadata metadata = buildMetadata(f);

                    uploads.startUploading(transferManager, f,
                            IOUtils.toBufferedInputStream(FileUtils.openInputStream(f)),
                            new Destination(bucketName, key), metadata);

                    if (uploads.count() > 20) {
                        waitForUploads(count, uploads);
                    }
                }
            }
        }
    });

    // Wait for each file to complete before returning
    waitForUploads(count, uploads);

    return uploads.count();
}

From source file:com.alibaba.jstorm.yarn.container.Executor.java

/**
 * check supervisor's heartBeat,//from  w  w  w .j a v a 2s . c  o m
 *
 * @return
 */
public boolean checkHeartBeat() {

    String dataPath = executorMeta.getLocalDir();
    File localstate = new File(dataPath + "/data/" + startType + "/" + startType + ".heartbeat/");
    Long modefyTime = localstate.lastModified();

    if (System.currentTimeMillis() - modefyTime > JOYConstants.EXECUTOR_HEARTBEAT_TIMEOUT) {

        LOG.info("----------------------");
        modefyTime = localstate.lastModified();
        LOG.info(modefyTime.toString());

        LOG.info(Long.toString(new Date().getTime()));
        LOG.info(dataPath + "/data/" + startType + "/" + startType + ".heartbeat/");

        LOG.info("can't get heartbeat over " + String.valueOf(JOYConstants.EXECUTOR_HEARTBEAT_TIMEOUT)
                + " seconds");
        return false;
    } else
        return true;
}

From source file:averroes.JarFile.java

/**
 * Add the given file with the given entry name to this JAR file.
 * /*  w  ww  .  j  ava 2  s .  c  o m*/
 * @param source
 * @param entryName
 * @throws IOException
 */
public void add(File source, String entryName) throws IOException {
    JarEntry entry = new JarEntry(entryName);
    entry.setTime(source.lastModified());
    getJarOutputStream().putNextEntry(entry);
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(source));

    byte[] buffer = new byte[1024];
    int len;
    while ((len = in.read(buffer)) != -1) {
        getJarOutputStream().write(buffer, 0, len);
    }
    getJarOutputStream().closeEntry();
    in.close();
}

From source file:net.pms.dlna.RealFile.java

public RealFile(File file, String name) {
    getConf().getFiles().add(file);
    getConf().setName(name);
    setLastModified(file.lastModified());
}

From source file:com.haulmont.cuba.gui.upload.FileUploading.java

@Override
public void clearTempDirectory() {
    try {/*from ww w  .  j ava  2 s  . c o  m*/
        File dir = new File(tempDir);
        File[] files = dir.listFiles();
        if (files == null)
            throw new IllegalStateException("Not a directory: " + tempDir);
        Date currentDate = timeSource.currentTimestamp();
        for (File file : files) {
            Date fileDate = new Date(file.lastModified());
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(fileDate);
            calendar.add(Calendar.DAY_OF_YEAR, 2);
            if (currentDate.compareTo(calendar.getTime()) > 0) {
                deleteFileLink(file.getAbsolutePath());
                if (!file.delete()) {
                    log.warn(String.format("Could not remove temp file %s", file.getName()));
                }
            }
        }
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }
}