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:com.att.aro.core.fileio.impl.FileManagerImpl.java

@Override
public long getLastModified(String filepath) {
    File file = new File(filepath);
    return file.lastModified();
}

From source file:com.cyclopsgroup.waterview.jelly.JellyPageRenderer.java

private synchronized Script getScript(String path) throws Exception {

    URL resource = getClass().getClassLoader().getResource(path);
    if (resource == null) {
        return null;
    }//from   www  .j  ava  2s.  co  m
    long timestamp = -1;

    if (reloadable) {
        File resourceFile = new File(resource.getPath());

        if (resourceFile.isFile()) {
            timestamp = resourceFile.lastModified();
        }
    }
    Script script = null;
    if (cache != null) {
        Entry entry = (Entry) cache.get(path);
        if (entry != null) {
            if (reloadable) {
                if (entry.timestamp >= timestamp) {
                    script = entry.script;
                }
            } else {
                script = entry.script;
            }
        }
    }
    if (script == null) {
        script = initialJellyContext.compileScript(resource);

        Entry entry = new Entry();
        entry.script = script;
        entry.timestamp = timestamp;
        if (cache != null) {
            cache.put(path, entry);
        }
    }
    return script;
}

From source file:bear.main.JavaCompiler2.java

public List<File> compileScripts(File sourcesDir) {
    FileFilter filter = new SuffixFileFilter(extensions);

    final File[] files = sourcesDir.listFiles(filter);

    final ArrayList<String> params = newArrayListWithExpectedSize(files.length);

    if (!buildDir.exists()) {
        buildDir.mkdir();/*  www.  j a v a2  s  .  com*/
    }

    Collections.addAll(params, "-d", buildDir.getAbsolutePath());
    List<File> javaFilesList = newArrayList(files);

    List<File> filesListToCompile = ImmutableList.copyOf(Iterables.filter(javaFilesList, new Predicate<File>() {
        @Override
        public boolean apply(File javaFile) {
            File classFile = new File(buildDir, FilenameUtils.getBaseName(javaFile.getName()) + ".class");

            boolean upToDate = classFile.exists() && classFile.lastModified() > javaFile.lastModified();

            if (upToDate) {
                logger.info("{} is up-to-date", javaFile);
            }

            return !upToDate;
        }
    }));

    if (filesListToCompile.isEmpty()) {
        logger.info("all files are up-to-date");
        return javaFilesList;
    }

    final List<String> filePaths = Lists.transform(filesListToCompile, new Function<File, String>() {
        public String apply(File input) {
            return input.getAbsolutePath();
        }
    });

    params.addAll(filePaths);

    logger.info("compiling {}", params);

    final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

    final int r = compiler.run(null, null, null, params.toArray(new String[params.size()]));

    if (r == 0) {
        logger.info("compilation OK.");
    } else {
        logger.info("compilation failed.");
    }

    return javaFilesList;
}

From source file:com.mobicage.rogerthat.util.CachedDownloader.java

public void cleanupOldCachedDownloads() {
    if (mExternalStorageWriteable) {
        File dir = getCachedDownloadDir();
        if (dir != null) {
            final long lastMonth = System.currentTimeMillis() - (30L * 86400L * 1000L);
            for (File file : dir.listFiles()) {
                if (file.lastModified() < lastMonth) {
                    if (!file.delete()) {
                        L.bug("Failed to delete old cached file with urlHash '" + file.getName() + "'");
                    }// w w  w.  ja va  2s .  c  o  m
                }
            }
        }
    }
    mMainService.postOnUIHandler(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            ConfigurationProvider configProvider = mMainService.getConfigurationProvider();
            Configuration cfg = configProvider.getConfiguration(CONFIGKEY);
            cfg.put(CONFIG_LAST_CLEANUP, System.currentTimeMillis());
            configProvider.updateConfigurationLater(CONFIGKEY, cfg);
        }
    });
}

From source file:com.glaf.template.TemplateReader.java

@SuppressWarnings("unchecked")
public Map<String, Template> getTemplates(InputStream inputStream) {
    Map<String, Template> dataMap = new java.util.HashMap<String, Template>();
    Element root = this.getRootElement(inputStream);
    List<?> templates = root.elements("template");
    if (templates != null && templates.size() > 0) {
        Iterator<?> iterator = templates.iterator();
        while (iterator.hasNext()) {
            Element element = (Element) iterator.next();
            Template template = new Template();

            List<Element> elems = element.elements();
            if (elems != null && !elems.isEmpty()) {
                Map<String, Object> rowMap = new java.util.HashMap<String, Object>();
                for (Element em : elems) {
                    rowMap.put(em.getName(), em.getStringValue());
                }/*  ww w .  j a  v  a  2 s.  c  om*/
                Tools.populate(template, rowMap);
            }

            String text = element.elementText("text");
            String name = element.elementText("name");
            String title = element.elementText("title");
            String templateId = element.attributeValue("id");
            String dataFile = element.elementText("dataFile");
            String moduleId = element.elementText("moduleId");
            String moduleName = element.elementText("moduleName");
            String callbackUrl = element.elementText("callbackUrl");
            String description = element.elementText("description");
            String language = element.elementText("language");
            String objectId = element.elementText("objectId");
            String objectValue = element.elementText("objectValue");
            String _fileType = element.elementText("fileType");

            template.setLanguage(language);

            int fileType = 0;
            if (StringUtils.isNumeric(_fileType)) {
                fileType = Integer.parseInt(_fileType);
            }
            if (dataFile.endsWith(".java")) {
                fileType = 50;
            } else if (dataFile.endsWith(".jsp")) {
                fileType = 51;
            } else if (dataFile.endsWith(".ftl")) {
                fileType = 52;
                template.setLanguage("freemarker");
            } else if (dataFile.endsWith(".vm")) {
                fileType = 54;
                template.setLanguage("velocity");
            } else if (dataFile.endsWith(".xml")) {
                fileType = 60;
            } else if (dataFile.endsWith(".htm") || dataFile.endsWith(".html")) {
                fileType = 80;
            }

            template.setTemplateType(FileUtils.getFileExt(dataFile));

            if (StringUtils.isEmpty(text)) {
                String filename = SystemProperties.getConfigRootPath() + dataFile;
                File file = new File(filename);
                template.setLastModified(file.lastModified());
                template.setFileSize(file.length());
                byte[] data = FileUtils.getBytes(file);
                template.setData(data);
            }
            if (template.getData() == null || template.getFileSize() == 0) {
                throw new RuntimeException(" template content is null ");
            }

            template.setContent(text);
            template.setDataFile(dataFile);
            template.setTitle(title);
            template.setName(name);
            if (StringUtils.isNotEmpty(name)) {
                template.setName(name);
            } else {
                template.setName(title);
            }
            template.setFileType(fileType);
            template.setCallbackUrl(callbackUrl);
            template.setDescription(description);
            template.setTemplateId(templateId);

            template.setModuleId(moduleId);
            template.setModuleName(moduleName);
            template.setObjectId(objectId);
            template.setObjectValue(objectValue);

            dataMap.put(templateId, template);
        }
    }

    return dataMap;
}

From source file:com.eleybourn.bookcatalogue.backup.tar.TarBackupWriter.java

/**
 * Save the books export file//from  w  w  w  . j  a v a2s.co  m
 */
@Override
public void putBooks(File books) throws IOException {
    TarArchiveEntry entry = new TarArchiveEntry(new File(TarBackupContainer.BOOKS_FILE));
    entry.setModTime(books.lastModified());
    entry.setSize(books.length());
    mOutput.putArchiveEntry(entry);
    FileInputStream in = new FileInputStream(books);
    streamToArchive(in);
}

From source file:maven.plugin.javafmt.JavaFormatterMojo.java

protected void updateStatus(File javaFile) {
    String propertyKey = javaFile.getAbsolutePath();
    String propertyValue = String.valueOf(javaFile.lastModified());
    ///*w  w  w .j  a v  a2  s .c  o  m*/
    status.setProperty(propertyKey, propertyValue);
}

From source file:com.citrixonline.android.utils.LocalAndroidSdk.java

public File lastFolderModified(File dir) {
    File[] files = dir.listFiles(new FileFilter() {
        public boolean accept(File file) {
            return file.isDirectory();
        }/*from ww w. java2  s.co m*/
    });
    long lastMod = Long.MIN_VALUE;
    File choice = null;
    for (File file : files) {
        if (file.lastModified() > lastMod) {
            choice = file;
            lastMod = file.lastModified();
        }
    }
    return choice;
}

From source file:com.qwazr.webapps.transaction.StaticManager.java

void handle(WebappHttpResponse response, File staticFile) throws IOException {
    String type = mimeTypeMap.getContentType(staticFile);
    if (type != null)
        response.setContentType(type);/*w  w w. ja  v  a2s .c om*/
    response.setContentLengthLong(staticFile.length());
    response.setDateHeader("Last-Modified", staticFile.lastModified());
    response.setHeader("Cache-Control", "max-age=86400");
    response.setDateHeader("Expires", System.currentTimeMillis() + 86400 * 1000);
    InputStream inputStream = new FileInputStream(staticFile);
    try {
        IOUtils.copy(inputStream, response.getOutputStream());
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:com.gitblit.servlet.PtServlet.java

@Override
protected long getLastModified(HttpServletRequest req) {
    File file = runtimeManager.getFileOrFolder("tickets.pt", "${baseFolder}/pt.py");
    if (file.exists()) {
        return Math.max(lastModified, file.lastModified());
    } else {//w w w .  j  a  v  a2 s  . c  o  m
        return lastModified;
    }
}