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; } }
/** * 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; }
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; } }
@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(); }
private static FileUploadResult getFileUploadResult( String keyspaceName, String columnFamilyName, Path file) throws Exception { BasicFileAttributes fileAttributes = Files.readAttributes(file, BasicFileAttributes.class); return new FileUploadResult( file, keyspaceName, columnFamilyName, fileAttributes.lastModifiedTime().toInstant(), fileAttributes.creationTime().toInstant(), fileAttributes.size()); }
final Date lastModified = Date.from(lastModifiedTime.toInstant()); final HashCode hashCode = Hashing.sha256().hashBytes(fileContents); final EntityTag entityTag = new EntityTag(hashCode.toString());
return; long lastModified = LocalDateTime.ofInstant(lastModifiedObj.toInstant(), ZoneId.of(ZoneOffset.systemDefault().getId())).toEpochSecond(ZoneOffset.UTC); String contentType = "video/mp4";
Instant lastMod = Files.getLastModifiedTime(path).toInstant(); processEtag(String.valueOf(lastMod.toEpochMilli()), request.headers(), response.headers()); processModifyHeaders(lastMod, request.headers(), response.headers());
private boolean canBeSafelyDeleted(Path path, Instant threshold) { try { return Files.getLastModifiedTime(path).toInstant().isBefore(threshold); } catch (IOException e) { LOG.warn(MessageFormat.format( JGitText.get().cannotAccessLastModifiedForSafeDeletion, path), e); return false; } }
public static LocalDateTime getLastAccessTime(File file) { LocalDateTime time; try { Path path = Paths.get(file.getAbsolutePath()); BasicFileAttributes fileattr = Files .getFileAttributeView(path, BasicFileAttributeView.class) .readAttributes(); time = LocalDateTime.ofInstant(fileattr.lastAccessTime().toInstant(), ZoneId.systemDefault()); } catch (Exception e) { time = null; } return time; }
public static LocalDateTime getCreationTime(File file) { LocalDateTime time; try { Path path = Paths.get(file.getAbsolutePath()); BasicFileAttributes fileattr = Files .getFileAttributeView(path, BasicFileAttributeView.class) .readAttributes(); time = LocalDateTime.ofInstant(fileattr.creationTime().toInstant(), ZoneId.systemDefault()); } catch (Exception e) { time = null; } return time; }
public static LocalDateTime getModificationTime(File file) { LocalDateTime time; try { Path path = Paths.get(file.getAbsolutePath()); BasicFileAttributes fileattr = Files .getFileAttributeView(path, BasicFileAttributeView.class) .readAttributes(); time = LocalDateTime.ofInstant(fileattr.lastModifiedTime().toInstant(), ZoneId.systemDefault()); } catch (Exception e) { time = null; } return time; }
private void deleteTempPacksIdx() { Path packDir = repo.getObjectDatabase().getPackDirectory().toPath(); Instant threshold = Instant.now().minus(1, ChronoUnit.DAYS); if (!Files.exists(packDir)) { return; } try (DirectoryStream<Path> stream = Files.newDirectoryStream(packDir, "gc_*_tmp")) { //$NON-NLS-1$ stream.forEach(t -> { try { Instant lastModified = Files.getLastModifiedTime(t) .toInstant(); if (lastModified.isBefore(threshold)) { Files.deleteIfExists(t); } } catch (IOException e) { LOG.error(e.getMessage(), e); } }); } catch (IOException e) { LOG.error(e.getMessage(), e); } }
private boolean autoGcBlockedByOldLockFile() { try { FileTime lastModified = Files.getLastModifiedTime(FileUtils.toPath(logFile)); if (lastModified.toInstant().compareTo(getLogExpiry()) > 0) { // There is an existing log file, which is too recent to ignore return true; } } catch (NoSuchFileException e) { // No existing log file, OK. } catch (IOException | ParseException e) { throw new JGitInternalException(e.getMessage(), e); } return false; }
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; } }
private void updateLastBuildRequest() throws IOException { Path buildRequestLogPath = serverDir.resolve(buildRequestLog); if (Files.isReadable(buildRequestLogPath)) { BasicFileAttributes buildAttrs = Files.readAttributes(buildRequestLogPath, BasicFileAttributes.class); lastBuildRequest = buildAttrs.lastModifiedTime().toInstant().plusSeconds(1); } else { lastBuildRequest = since; } }
@Nonnull public Instant getLastAccessTime() { return getHandle().getLastAccessTime().toInstant(); }
public static LocalDateTime getLastAccessTime(File file) { LocalDateTime time; try { Path path = Paths.get(file.getAbsolutePath()); BasicFileAttributes fileattr = Files .getFileAttributeView(path, BasicFileAttributeView.class) .readAttributes(); time = LocalDateTime.ofInstant(fileattr.lastAccessTime().toInstant(), ZoneId.systemDefault()); } catch (Exception e) { time = null; } return time; }
@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(); }
@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(); }