Refine search
public static Memory filectime(Environment env, TraceInfo trace, String path) { Path file = Paths.get(path); try { BasicFileAttributes attributes = Files.readAttributes(file, BasicFileAttributes.class); return LongMemory.valueOf(attributes.creationTime().toMillis() / 1000); } catch (IOException e) { env.warning(trace, e.getMessage()); return Memory.FALSE; } catch (UnsupportedOperationException e) { return Memory.FALSE; } }
protected void setLastModified(FileVersion reconstructedFileVersion, File reconstructedFilesAtFinalLocation) { // Using Files.setLastModifiedTime() instead of File.setLastModified() // due to pre-1970 issue. See #374 for details. try { FileTime newLastModifiedTime = FileTime.fromMillis(reconstructedFileVersion.getLastModified().getTime()); Files.setLastModifiedTime(reconstructedFilesAtFinalLocation.toPath(), newLastModifiedTime); } catch (IOException e) { logger.log(Level.WARNING, "Warning: Could not set last modified date for file " + reconstructedFilesAtFinalLocation + "; Ignoring error.", e); } }
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; } }
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); }
Path path = Paths.get(toUri(url)); if (Files.isDirectory(path)) { try (DirectoryStream<Path> files = Files.newDirectoryStream(path)) { for (Path file : files) { builder.append(file.getFileName()).append('\n'); length = bytes.length; } else { stream = Files.newInputStream(path); length = Files.size(path); DateFormat format = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US); format.setTimeZone(TimeZone.getTimeZone("GMT")); builder.put("last-modified", format.format(new Date(lastModified.toMillis())));
@Override public Date getLastModified() { try { return new Date(Files.getLastModifiedTime(file).toMillis()); } catch (IOException e) { throw new RuntimeException(e); } }
private static List<GameInfo> getSavedGameOrRecording(Path saveOrRecordingPath) { SortedMap<FileTime, Path> savedGamePaths = Maps.newTreeMap(Collections.reverseOrder()); try (DirectoryStream<Path> stream = Files.newDirectoryStream(saveOrRecordingPath)) { for (Path entry : stream) { if (Files.isRegularFile(entry.resolve(GameManifest.DEFAULT_FILE_NAME))) { savedGamePaths.put(Files.getLastModifiedTime(entry.resolve(GameManifest.DEFAULT_FILE_NAME)), entry); Path gameManifest = world.getValue().resolve(GameManifest.DEFAULT_FILE_NAME); if (!Files.isRegularFile(gameManifest)) { try { if (!info.getTitle().isEmpty()) { Date date = new Date(world.getKey().toMillis()); result.add(new GameInfo(info, date, world.getValue()));
final Path directoryPath = new File(getPath(context)).toPath(); final Path relativePath = directoryPath.toAbsolutePath().relativize(filePath.getParent()); String relativePathString = relativePath.toString(); relativePathString = relativePathString.isEmpty() ? "." + File.separator : relativePathString + File.separator; attributes.put(CoreAttributes.ABSOLUTE_PATH.key(), absPathString); attributes.put(FILE_SIZE_ATTRIBUTE, Long.toString(fileInfo.getSize())); attributes.put(FILE_LAST_MODIFY_TIME_ATTRIBUTE, formatter.format(new Date(fileInfo.getLastModifiedTime()))); FileStore store = Files.getFileStore(filePath); BasicFileAttributeView view = Files.getFileAttributeView(filePath, BasicFileAttributeView.class); BasicFileAttributes attrs = view.readAttributes(); attributes.put(FILE_CREATION_TIME_ATTRIBUTE, formatter.format(new Date(attrs.creationTime().toMillis()))); attributes.put(FILE_LAST_ACCESS_TIME_ATTRIBUTE, formatter.format(new Date(attrs.lastAccessTime().toMillis()))); } catch (Exception ignore) { if (store.supportsFileAttributeView("owner")) { try { FileOwnerAttributeView view = Files.getFileAttributeView(filePath, FileOwnerAttributeView.class); attributes.put(FILE_OWNER_ATTRIBUTE, view.getOwner().getName()); } catch (Exception ignore) {
/** * @param fileName * @param directory * @param attrs */ public FileInfo(String fileName, boolean directory, BasicFileAttributes attrs) { this.fileName = fileName; this.directory = directory; this.lastModifiedTime = new Date(attrs.lastModifiedTime().toMillis()); this.lastAccessTime = new Date(attrs.lastAccessTime().toMillis()); this.creationTime = new Date(attrs.creationTime().toMillis()); this.size = attrs.size(); }
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(); }
/** * prints out details about the specified path * such as size and modification time * @param file * @throws IOException */ private void print(Path file) throws IOException{ final DateFormat df = new SimpleDateFormat("MM/dd/yyyy-HH:mm:ss"); final String modTime= df.format(new Date( Files.getLastModifiedTime(file).toMillis())); if(logger.isDebugEnabled()) { logger.debug("%d %s %s", Files.size(file), modTime, file); } } });
protected Map<String, String> getAttributesFromFile(final Path file) { Map<String, String> attributes = new HashMap<>(); try { FileStore store = Files.getFileStore(file); if (store.supportsFileAttributeView("basic")) { try { final DateFormat formatter = new SimpleDateFormat(FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US); BasicFileAttributeView view = Files.getFileAttributeView(file, BasicFileAttributeView.class); BasicFileAttributes attrs = view.readAttributes(); attributes.put(FILE_LAST_MODIFY_TIME_ATTRIBUTE, formatter.format(new Date(attrs.lastModifiedTime().toMillis()))); attributes.put(FILE_CREATION_TIME_ATTRIBUTE, formatter.format(new Date(attrs.creationTime().toMillis()))); attributes.put(FILE_LAST_ACCESS_TIME_ATTRIBUTE, formatter.format(new Date(attrs.lastAccessTime().toMillis()))); } catch (Exception ignore) { FileOwnerAttributeView view = Files.getFileAttributeView(file, FileOwnerAttributeView.class); attributes.put(FILE_OWNER_ATTRIBUTE, view.getOwner().getName()); } catch (Exception ignore) {
if ( !Files.isDirectory( pluginsDirectory ) || !Files.isReadable( pluginsDirectory ) ) final String fileName = jarFile.getFileName().toString(); final String canonicalPluginName = fileName.substring( 0, fileName.length() - 4 ).toLowerCase(); // strip extension. if ( Files.exists( dir ) && Files.getLastModifiedTime( jarFile ).toMillis() > Files.getLastModifiedTime( dir ).toMillis() ) final Path devPluginPath = Paths.get( devPluginDir ); if ( Files.exists( devPluginPath ) && Files.isDirectory( devPluginPath ) )
final Pattern pathPattern = (!recurseDirs || pathPatternStr == null) ? null : Pattern.compile(pathPatternStr); final Path basePath = Paths.get(indir); if (minSize > attributes.size()) { return false; if (maxSize != null && maxSize < attributes.size()) { return false; final long fileAge = System.currentTimeMillis() - attributes.lastModifiedTime().toMillis(); if (minAge > fileAge) { return false; final Path relativePath = basePath.relativize(path).getParent(); final String relativeDir = relativePath == null ? "" : relativePath.toString(); final String filename = path.getFileName().toString(); final TimingInfo timingInfo = performanceTracker.getTimingInfo(relativeDir, filename); if (!timingInfo.timeOperation(DiskOperation.CHECK_READABLE, () -> Files.isReadable(path))) { return false;
return new MultipartFileSender().setFilepath(Paths.get(uri)); if (!Files.exists(filepath)) { logger.error("File doesn't exist at URI : {}", filepath.toAbsolutePath().toString()); response.sendError(HttpServletResponse.SC_NOT_FOUND); return; Long length = Files.size(filepath); String fileName = filepath.getFileName().toString(); FileTime lastModifiedObj = Files.getLastModifiedTime(filepath); return; long lastModified = LocalDateTime.ofInstant(lastModifiedObj.toInstant(), ZoneId.of(ZoneOffset.systemDefault().getId())).toEpochSecond(ZoneOffset.UTC); String contentType = "video/mp4";
final String targetFileName = targetFileName(templatesPath.relativize(input.path).toString(), templateOptions); final OutputFile output = new OutputFile(outputPath.resolve(targetFileName).toAbsolutePath().normalize()); Files.exists(output.path) && Files.getLastModifiedTime(output.path).toMillis() >= Files.getLastModifiedTime(input.path).toMillis()) {
@Override public boolean accept(Path path) throws IOException { if (!path.toFile().exists()) { return false; } if (!path.getFileName().toString().startsWith(TMP_NAME_PREFIX)) { return false; } long threshold = System.currentTimeMillis() - CLEAN_MAX_AGE; // we could also check the timestamp in the name, instead BasicFileAttributes attrs; try { attrs = Files.readAttributes(path, BasicFileAttributes.class); } catch (IOException ioe) { LOG.error(String.format("Couldn't read file attributes for %s : ", path), ioe); return false; } long creationTime = attrs.creationTime().toMillis(); return creationTime < threshold; } }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { long ageInMs = now.getTime() - attrs.lastAccessTime().toMillis(); long ageInMin = TimeUnit.MINUTES.convert(ageInMs, TimeUnit.MILLISECONDS); if (ageInMin >= cleanupAge) { Files.delete(file); log.fine("Deleted file " + file); } return FileVisitResult.CONTINUE; }
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; } }
final long start = System.currentTimeMillis(); final String key = SingularityS3FormatHelper.getKey(uploadMetadata.getS3KeyFormat(), sequence, Files.getLastModifiedTime(file).toMillis(), Objects.toString(file.getFileName()), hostname); long fileSizeBytes = Files.size(file); LOG.info("{} Uploading {} to {}/{} (size {})", logIdentifier, file, bucketName, key, fileSizeBytes); if (file.toString().endsWith(contentHeaders.getFilenameEndsWith())) { LOG.debug("{} Using content headers {} for file {}", logIdentifier, contentHeaders, file); if (contentHeaders.getContentType().isPresent()) { try (FileInputStream fileInputStream = new FileInputStream(file.toFile())){ if (uploadMetadata.getEncryptionKey().isPresent()) { storage.create(blobInfoBuilder.build(), fileInputStream, BlobWriteOption.encryptionKey(uploadMetadata.getEncryptionKey().get()));