/** * This implementation returns the underlying File's timestamp. * @see java.nio.file.Files#getLastModifiedTime(Path, java.nio.file.LinkOption...) */ @Override public long lastModified() throws IOException { // We can not use the superclass method since it uses conversion to a File and // only a Path on the default file system can be converted to a File... return Files.getLastModifiedTime(this.path).toMillis(); }
@Override public Object getCurrentState(final Path path) throws IOException { return Files.getLastModifiedTime(path); }
private Long lastModifiedMs(String path) { try { return Files.getLastModifiedTime(Paths.get(path)).toMillis(); } catch (IOException e) { log.error("Modification time of key store could not be obtained: " + path, e); return null; } }
/** * This implementation returns the underlying File's timestamp. * @see java.nio.file.Files#getLastModifiedTime(Path, java.nio.file.LinkOption...) */ @Override public long lastModified() throws IOException { // We can not use the superclass method since it uses conversion to a File and // only a Path on the default file system can be converted to a File... return Files.getLastModifiedTime(this.path).toMillis(); }
private static long getFileModDate(String path) { try { return Files.getLastModifiedTime(Paths.get(path)).toMillis(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Date getLastModified() { try { return new Date(Files.getLastModifiedTime(file).toMillis()); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public long lastModifiedTime( File file ) { try { return Files.getLastModifiedTime( path( file ) ).toMillis(); } catch ( IOException e ) { return 0; } }
/** * This implementation returns the underlying File/Path last-modified time. */ @Override public long lastModified() throws IOException { if (this.file != null) { return super.lastModified(); } else { try { return Files.getLastModifiedTime(this.filePath).toMillis(); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } } }
private synchronized void writeToFile() { try { Files.write(cacheFile, Jsons.toJson(cache).getBytes(Constants.UTF_8)); this.lastModified = Files.getLastModifiedTime(cacheFile).toMillis(); } catch (Exception e) { e.printStackTrace(); } }
private synchronized void loadFormFile() { try { long lastModified = Files.getLastModifiedTime(cacheFile).toMillis(); if (this.lastModified < lastModified) { byte[] bytes = Files.readAllBytes(cacheFile); if (bytes != null && bytes.length > 0) { cache = Jsons.fromJson(bytes, ConcurrentHashMap.class); } this.lastModified = lastModified; } } catch (Exception e) { e.printStackTrace(); } }
private Instant getLastModified(String path) throws IOException { Path file = Paths.get(path); if (Files.exists(file) && Files.isRegularFile(file)) { return Files.getLastModifiedTime(file).toInstant(); } else { return null; } }
private void calculateChangeOverPoint() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.add(Calendar.DATE, 1); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US); currentDateString = df.format(new Date()); // if there is an existing default log file, use the date last modified instead of the current date if (Files.exists(defaultLogFile)) { try { currentDateString = df.format(new Date(Files.getLastModifiedTime(defaultLogFile).toMillis())); } catch(IOException e){ // ignore. use the current date if exception happens. } } changeOverPoint = calendar.getTimeInMillis(); }
private static String getOldestFileName(final List<Path> paths) { FileTime oldestTime = null; Path oldestPath = null; for (Path path : paths) { try { final FileTime fileTime = Files.getLastModifiedTime(path); if (oldestTime == null || fileTime.compareTo(oldestTime) < 0) { oldestTime = fileTime; oldestPath = path; } } catch (IOException e) { logger.error("Can't read last modified time for path {}", path); } } if (oldestPath != null) { return oldestPath.getFileName().toString(); } return DEFAULT_PREVIEW_NAME; }
/** * Returns the last modified time of the given file or directory. * * @param path a file or directory * @return the last modified time */ public static Instant lastModifiedTime(Path path) { try { return Files.getLastModifiedTime(path.toRealPath()).toInstant(); } catch (IOException e) { LOGGER.log(Level.FINE, e, () -> "Cannot obtain the last modified time of '" + path + "'."); } Instant timestamp = Instant.MAX; LOGGER.finer("Cannot obtain the last modified time. Used time '" + timestamp + "' as a content timestamp."); return timestamp; }
public static Memory filemtime(Environment env, TraceInfo trace, String path) { Path file = Paths.get(path); try { return LongMemory.valueOf(Files.getLastModifiedTime(file).toMillis() / 1000); } catch (IOException e) { env.warning(trace, e.getMessage()); return Memory.FALSE; } catch (UnsupportedOperationException e) { return Memory.FALSE; } }
/** * This implementation returns the underlying File/Path last-modified time. */ @Override public long lastModified() throws IOException { if (this.file != null) { return super.lastModified(); } else { try { return Files.getLastModifiedTime(this.filePath).toMillis(); } catch (NoSuchFileException ex) { throw new FileNotFoundException(ex.getMessage()); } } }
static Instant resourceTimestamp(String resourceName) { try { Path resourcePath = resourcePath(resourceName); if (resourcePath != null) { return Files.getLastModifiedTime(resourcePath).toInstant(); } } catch (Exception ex) { LOGGER.log(Level.FINE, "Error to get resource '" + resourceName + "' last modified time.", ex); } return Instant.EPOCH; } }
@Override public long getLastModified(final Path handle) { return Try.apply(() -> Files.getLastModifiedTime(handle).toMillis()).orElse(-1L); }
@VisibleForTesting LayerEntryTemplate(LayerEntry layerEntry) throws IOException { sourceFile = layerEntry.getSourceFile().toAbsolutePath().toString(); extractionPath = layerEntry.getExtractionPath().toString(); lastModifiedTime = Files.getLastModifiedTime(layerEntry.getSourceFile()).toInstant(); permissions = layerEntry.getPermissions().toOctalString(); }
public void testTouchTime() throws IOException { Path temp = createTempFile(); assertTrue(Files.exists(temp)); Files.setLastModifiedTime(temp, FileTime.fromMillis(0)); assertEquals(0, Files.getLastModifiedTime(temp).toMillis()); MoreFiles.touch(temp); assertThat(Files.getLastModifiedTime(temp).toMillis()).isNotEqualTo(0); }