List of usage examples for java.io File lastModified
public long lastModified()
From source file:org.shredzone.commons.gravatar.impl.GravatarServiceImpl.java
/** * Checks if the file cache lifetime is expired. * * @param file//from ww w . j a v a2 s.c om * {@link File} to check * @return {@code true} if the file is older than cache lifetime */ private boolean isExpired(File file) { long fileTs = file.lastModified(); long expiryTs = System.currentTimeMillis() - (aliveSeconds * 1000L); return (fileTs < expiryTs); }
From source file:jobhunter.persistence.Persistence.java
private void updateLastMod(final File file) { this.lastModification = file.lastModified(); try (InputStream in = new FileInputStream(file)) { this.md5sum = DigestUtils.md5(in); } catch (IOException e) { l.error("Failed to read MD5 checksum from {}", file.toString(), e); }/*from w w w . jav a 2 s .c o m*/ l.debug("File was last modified on {} with MD5 {}", lastModification, this.md5sum.toString()); }
From source file:com.stehno.sanctuary.core.local.JdbcLocalStore.java
@Override public void storeFile(File file) { removeFile(file);/*from w ww .j a va2 s . com*/ jdbcTemplate.update( storeFileFactory.newPreparedStatementCreator(new Object[] { file.getPath(), file.lastModified() })); }
From source file:it.grid.storm.authz.sa.conf.FileAuthzDBReloadingStrategy.java
/** * Check if the configuration has changed since the last time it was loaded. * //from w w w . j av a2 s. c o m * @return a flag whether the configuration has changed */ @Override protected boolean hasChanged() { File file = getConfigurationFile(); if (file == null || !file.exists()) { return false; } boolean result = file.lastModified() > lastModified; if (result) { notifyNeeded(); log.debug(" AuthZ DB {} is CHANGED ---> Notify needed..", file.getName()); } return result; }
From source file:hudson.util.DoubleLaunchChecker.java
protected void execute() { File timestampFile = new File(home, ".owner"); long t = timestampFile.lastModified(); if (t != 0 && lastWriteTime != 0 && t != lastWriteTime && !ignore) { try {// w w w .j a v a 2s .c o m collidingId = FileUtils.readFileToString(timestampFile); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Failed to read collision file", e); } // we noticed that someone else have updated this file. // switch GUI to display this error. Hudson.getInstance().servletContext.setAttribute("app", this); LOGGER.severe("Collision detected. timestamp=" + t + ", expected=" + lastWriteTime); // we need to continue updating this file, so that the other Hudson would notice the problem, too. } try { FileUtils.writeStringToFile(timestampFile, getId()); lastWriteTime = timestampFile.lastModified(); } catch (IOException e) { // if failed to write, err on the safe side and assume things are OK. lastWriteTime = 0; } schedule(); }
From source file:com.nadmm.airports.wx.NoaaService.java
private void cleanupCache(File dir, long maxAge) { // Delete all files that are older Date now = new Date(); File[] files = dir.listFiles(); for (File file : files) { long age = now.getTime() - file.lastModified(); if (age > maxAge) { file.delete();// ww w.jav a 2 s. co m } } }
From source file:com.sms.server.service.parser.NFOParser.java
public boolean isUpdateRequired(String path, Timestamp lastScanned) { File nfoFile = getNFOFile(path); if (nfoFile == null) { return false; }/*w ww .ja v a2s . co m*/ return new Timestamp(nfoFile.lastModified()).after(lastScanned); }
From source file:com.eviware.loadui.impl.conversion.FileToReferenceConverter.java
private synchronized String getHash(File file) { String key = file.getAbsolutePath(); if (!cache.containsKey(key) || cache.get(key).modified != file.lastModified()) { try {/*from www .j av a2s.com*/ String hash = DigestUtils.md5Hex(new FileInputStream(file)); cache.put(key, new FileStruct(hash, file.lastModified())); lookupTable.put(hash, file); } catch (IOException e) { throw new RuntimeException("Error calculating hash of file [" + file.getName() + "].", e); } } return cache.get(key).hash; }
From source file:com.zimbra.cs.service.util.ItemDataFile.java
static void addFile(File f, String topdir, Set<MailItem.Type> types, TarOutputStream tos) throws IOException { ItemData id = null;/*from w w w. j a v a 2 s . c o m*/ String path = f.getPath(); File mf = new File(path + ".meta"); TarEntry te; MailItem.Type type; if (path.indexOf(topdir) == 0) path = path.substring(topdir.length() + 1); path = path.replace('\\', '/'); if (mf.exists()) { byte[] meta = new byte[(int) mf.length()]; FileInputStream fis = new FileInputStream(mf); if (fis.read(meta) != mf.length()) { throw new IOException("meta read err: " + f.getPath()); } fis.close(); id = new ItemData(meta); type = MailItem.Type.of(id.ud.type); if (skip(types, type)) { return; } te = new TarEntry(path + ".meta"); System.out.println(te.getName()); te.setGroupName(MailItem.Type.of(id.ud.type).toString()); te.setMajorDeviceId(id.ud.type); te.setModTime(mf.lastModified()); te.setSize(meta.length); tos.putNextEntry(te); tos.write(meta); tos.closeEntry(); } else { if (path.endsWith(".csv") || path.endsWith(".vcf")) { type = MailItem.Type.CONTACT; } else if (path.endsWith(".eml")) { type = MailItem.Type.MESSAGE; } else if (path.endsWith(".ics")) { if (path.startsWith("Tasks/")) { type = MailItem.Type.TASK; } else { type = MailItem.Type.APPOINTMENT; } } else if (path.endsWith(".wiki")) { type = MailItem.Type.WIKI; } else { type = MailItem.Type.DOCUMENT; } if (skip(types, type)) { } return; } if (f.exists() && !f.isDirectory() && (id != null || types == null)) { byte[] buf = new byte[TarBuffer.DEFAULT_BLKSIZE]; FileInputStream fis = new FileInputStream(f); int in; te = new TarEntry(path); System.out.println(te.getName()); te.setGroupName(MailItem.Type.of(id.ud.type).toString()); te.setMajorDeviceId(id.ud.type); te.setModTime(mf.lastModified()); te.setSize(f.length()); tos.putNextEntry(te); while ((in = fis.read(buf)) > 0) tos.write(buf, 0, in); fis.close(); tos.closeEntry(); } }
From source file:com.github.k0zka.contentcompress.ContentGzipMojo.java
void compress(final File directory, final String fileName) throws IOException { final File sourceFile = new File(directory, fileName); final File gzippedFile = new File(directory, fileName.concat(".gz")); if (gzippedFile.exists() && gzippedFile.lastModified() > sourceFile.lastModified()) { getLog().info("Skipped file " + sourceFile.getName() + " .gz is up to date"); return;//from w ww. jav a 2 s .c om } final FileInputStream inputStream = new FileInputStream(sourceFile); final FileOutputStream fileStream = new FileOutputStream(gzippedFile); final GZIPOutputStream gzipStream = new GZIPOutputStream(fileStream); IOUtils.copy(inputStream, gzipStream); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(gzipStream); IOUtils.closeQuietly(fileStream); final long sourceLength = sourceFile.length(); final long gzipedLength = gzippedFile.length(); if (sourceLength > gzipedLength) { getLog().info("Compressed file " + sourceFile.getName() + ". " + sourceLength + " -> " + gzipedLength); } else { getLog().info("Compressed file " + sourceFile.getName() + ". " + sourceLength + " -> " + gzipedLength + " removing, gzipped version is bigger"); gzippedFile.delete(); } }