List of usage examples for java.io File lastModified
public long lastModified()
From source file:data.NeustarDatabaseUpdaterTest.java
@Test public void itDeterminesLatestBuildDate() { assertThat(neustarDatabaseUpdater.getDatabaseBuildDate(), nullValue()); File file = mock(File.class); when(file.lastModified()).thenReturn(1425236082000L); when(neustarDatabaseDirectory.listFiles()).thenReturn(new File[] { file }); assertThat(neustarDatabaseUpdater.getDatabaseBuildDate(), equalTo(new Date(1425236082000L))); }
From source file:oz.hadoop.yarn.api.utils.JarUtils.java
/** * * @param source/* w w w. ja v a 2 s.c o m*/ * @param lengthOfOriginalPath * @param target * @throws IOException */ private static void add(File source, int lengthOfOriginalPath, JarOutputStream target) throws IOException { BufferedInputStream in = null; try { String path = source.getAbsolutePath(); path = path.substring(lengthOfOriginalPath); if (source.isDirectory()) { String name = path.replace("\\", "/"); if (!name.isEmpty()) { if (!name.endsWith("/")) { name += "/"; } JarEntry entry = new JarEntry(name.substring(1)); // avoiding absolute path warning target.putNextEntry(entry); target.closeEntry(); } for (File nestedFile : source.listFiles()) { add(nestedFile, lengthOfOriginalPath, target); } return; } JarEntry entry = new JarEntry(path.replace("\\", "/").substring(1)); // avoiding absolute path warning entry.setTime(source.lastModified()); try { target.putNextEntry(entry); in = new BufferedInputStream(new FileInputStream(source)); byte[] buffer = new byte[1024]; while (true) { int count = in.read(buffer); if (count == -1) { break; } target.write(buffer, 0, count); } target.closeEntry(); } catch (Exception e) { String message = e.getMessage(); if (StringUtils.hasText(message)) { if (!message.toLowerCase().contains("duplicate")) { throw new IllegalStateException(e); } logger.warn(message); } else { throw new IllegalStateException(e); } } } finally { if (in != null) in.close(); } }
From source file:com.afis.jx.ckfinder.connector.utils.FileUtils.java
/** * Parse date with pattern yyyyMMddHHmm. Pattern is used in get file command response XML. * * @param file input file./*from w w w .j a v a 2 s . co m*/ * @return parsed file modification date. */ public static String parseLastModifDate(final File file) { Date date = new Date(file.lastModified()); DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm"); return dateFormat.format(date); }
From source file:corner.hadoop.services.impl.LocalFileAccessorProxy.java
/** * @see corner.hadoop.services.DistributedResourceAccessor#getFileMTTime(java.lang.String) *//* www .j av a 2 s . co m*/ @Override public long getFileMTTime(String filePath) throws IOException { File file = new File(addRootPath(filePath)); return file.lastModified(); }
From source file:com.google.acre.script.JSFile.java
public long jsGet_mtime() { File f = new File(_filename); return f.lastModified(); }
From source file:gridgrid.Web.java
private synchronized void load(File file) throws IOException { if (file.lastModified() > lastModified) { map = new HashMap<>(); InputStream is = new FileInputStream(file); Workbook book = new XSSFWorkbook(is); Sheet sheet = book.getSheetAt(0); int pathCelNum = -1; int scriptCellNum = -1; int viewCellNum = -1; for (int rowIndex = 1; rowIndex <= sheet.getLastRowNum(); rowIndex++) { Row row = sheet.getRow(rowIndex); if (row != null) { if (row.getLastCellNum() >= 1 && pathCelNum == -1) { for (int cellIndex = 0; cellIndex < row.getLastCellNum(); cellIndex++) { Cell cell = row.getCell(cellIndex); if (cell != null) { switch (cell.getStringCellValue()) { case "": pathCelNum = cellIndex; break; case "JavaScript": scriptCellNum = cellIndex; break; case "": viewCellNum = cellIndex; break; }/*from w w w . ja v a 2 s . c o m*/ } } } if (pathCelNum != -1 && row.getCell(pathCelNum) != null && row.getCell(scriptCellNum) != null && row.getCell(viewCellNum) != null) { Cell code = row.getCell(scriptCellNum); String codeStr = code != null ? code.toString() : ""; Cell view = row.getCell(viewCellNum); String viewStr = view != null ? view.toString() : ""; String path = row.getCell(pathCelNum).toString(); map.put(path, new CodeView(codeStr, viewStr)); } } } is.close(); lastModified = file.lastModified(); } }
From source file:edu.lternet.pasta.datapackagemanager.ArchiveCleaner.java
/** * Removes any archive file that is older than the specified time-to-live (ttl). * /* w w w .j a v a 2s. c o m*/ * @param ttl The time-to-live value in milliseconds. * @return the number of archive files that were removed */ public int doClean(Long ttl) { File tmpDir = new File(this.tmpDir); String[] ext = { "zip" }; Long time = new Date().getTime(); Long lastModified = null; int deleteCount = 0; Collection<File> files = FileUtils.listFiles(tmpDir, ext, false); for (File file : files) { if (file != null && file.exists()) { lastModified = file.lastModified(); // Remove file if older than the ttl if (lastModified + ttl <= time) { try { FileUtils.forceDelete(file); deleteCount++; } catch (IOException e) { logger.error(e.getMessage()); e.printStackTrace(); } } } } return deleteCount; }
From source file:com.temenos.interaction.loader.classloader.CachingParentLastURLClassloaderFactory.java
protected Object calculateCurrentState(FileEvent<File> param) { Collection<File> files = FileUtils.listFiles(param.getResource(), new String[] { "jar" }, true); MessageDigest md = DigestUtils.getMd5Digest(); for (File f : files) { md.update(Longs.toByteArray(f.lastModified())); }/* w w w. jav a2s. co m*/ Object state = Hex.encodeHexString(md.digest()); LOGGER.trace( "Calculated representation /hash/ of state of collection of URLs for classloader creation to: {}", state); return state; }
From source file:biz.gabrys.maven.plugins.directory.content.CopyMojo.java
private void copy(final File source, final File destination) throws MojoFailureException { if (!force && destination.exists() && source.lastModified() < destination.lastModified()) { if (verbose) { getLog().info("Skips copy file, because source is older than destination file: " + destination.getAbsolutePath()); }/*from www . j a va2s .c om*/ return; } if (verbose) { getLog().info( String.format("Copying %s to %s", source.getAbsolutePath(), destination.getAbsolutePath())); } try { FileUtils.copyFile(source, destination); } catch (final IOException e) { final String message = String.format("Cannot copy %s to %s", source.getAbsolutePath(), destination.getAbsolutePath()); throw new MojoFailureException(message, e); } }
From source file:org.killbill.billing.plugin.meter.timeline.persistent.Replayer.java
public void purgeOldFiles(final DateTime purgeIfOlderDate) { final List<File> candidates = findCandidates(); for (final File file : candidates) { if (file.lastModified() <= purgeIfOlderDate.getMillis()) { if (!file.delete()) { log.warn("Unable to delete file: {}", file.getAbsolutePath()); }/*from w w w . ja va 2 s . com*/ } } }