lastModif = Files.getLastModifiedTime(file.toPath()).to(TimeUnit.MILLISECONDS);
private boolean needsUpdate(@NotNull final Path pTargetPath, @NotNull final Path pSourcePath) throws IOException { boolean result = true; if (Files.exists(pTargetPath)) { final long sizeSource = Files.size(pSourcePath); final long sizeTarget = Files.size(pTargetPath); final long modTimeSecsSource = Files.getLastModifiedTime(pSourcePath).to(TimeUnit.SECONDS); final long modTimeSecsTarget = Files.getLastModifiedTime(pTargetPath).to(TimeUnit.SECONDS); result = sizeSource != sizeTarget || modTimeSecsSource != modTimeSecsTarget; } return result; }
private void init() throws IOException { if (!Files.exists(path)) throw new FileNotFoundException("File not found " + path); if (!Files.isReadable(path)) throw new IOException("File not readable"); length = Files.size(path); lastModified = Files.getLastModifiedTime(path).to(TimeUnit.MILLISECONDS); }
@Override public PropertiesCollector collect(final File file) { try { BasicFileAttributes attributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class); date = new Date(attributes.creationTime().to(TimeUnit.MILLISECONDS)); } catch (IOException e) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, e.getLocalizedMessage(), e); } } return this; }
private static double fromFileTime(FileTime fileTime) { return fileTime.to(TimeUnit.NANOSECONDS) / 1e9; }
private void init() throws IOException { if (!Files.exists(path)) throw new FileNotFoundException("File not found " + path); if (!Files.isReadable(path)) throw new IOException("File not readable"); length = Files.size(path); lastModified = Files.getLastModifiedTime(path).to(TimeUnit.MILLISECONDS); }
/** * Converts FileTime to "standard Unix time". */ @Substitute public static final long fileTimeToUnixTime(FileTime ftime) { return ftime.to(TimeUnit.SECONDS); }
private boolean isExpired(File file) throws IOException { final BasicFileAttributes fileAttributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class); final long to = fileAttributes.lastModifiedTime().to(TimeUnit.MILLISECONDS); final long currentTime = System.currentTimeMillis(); final long expirationTime = TimeUnit.MILLISECONDS.convert(this.expirationTime, this.timeUnit); if (to + expirationTime < currentTime) { return true; } return false; }
private boolean isExpired(File file) throws IOException { final BasicFileAttributes fileAttributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class); final long to = fileAttributes.lastModifiedTime().to(TimeUnit.MILLISECONDS); final long currentTime = System.currentTimeMillis(); final long expirationTime = TimeUnit.MILLISECONDS.convert(this.expirationTime, this.timeUnit); if (to + expirationTime < currentTime) { return true; } return false; }
@Override public long getModifiedTime( Properties conf ) throws IOException { return Files.getLastModifiedTime( getPath() ).to( TimeUnit.MILLISECONDS ); }
/** * Converts FileTime to Windows time. */ @Substitute public static final long fileTimeToWinTime(FileTime ftime) { return (ftime.to(TimeUnit.MICROSECONDS) - WINDOWS_EPOCH_IN_MICROSECONDS) * 10; }
/** * Encodes a {@link FileTime} value into a buffer * * @param buffer The target {@link Buffer} * @param version The encoding version * @param flags The encoding flags * @param time The value to encode */ public static void writeTime(Buffer buffer, int version, int flags, FileTime time) { // for v3 see https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02#page-8 // for v6 see https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#page-16 if (version >= SftpConstants.SFTP_V4) { buffer.putLong(time.to(TimeUnit.SECONDS)); if ((flags & SftpConstants.SSH_FILEXFER_ATTR_SUBSECOND_TIMES) != 0) { long nanos = time.to(TimeUnit.NANOSECONDS); nanos = nanos % TimeUnit.SECONDS.toNanos(1); buffer.putInt((int) nanos); } } else { buffer.putInt(time.to(TimeUnit.SECONDS)); } }
/** * Encodes a {@link FileTime} value into a buffer * * @param <B> Type of {@link Buffer} being updated * @param buffer The target buffer instance * @param version The encoding version * @param flags The encoding flags * @param time The value to encode * @return The updated buffer */ public static <B extends Buffer> B writeTime(B buffer, int version, int flags, FileTime time) { // for v3 see https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02#page-8 // for v6 see https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#page-16 if (version >= SftpConstants.SFTP_V4) { buffer.putLong(time.to(TimeUnit.SECONDS)); if ((flags & SftpConstants.SSH_FILEXFER_ATTR_SUBSECOND_TIMES) != 0) { long nanos = time.to(TimeUnit.NANOSECONDS); nanos = nanos % TimeUnit.SECONDS.toNanos(1); buffer.putInt((int) nanos); } } else { buffer.putInt(time.to(TimeUnit.SECONDS)); } return buffer; }
private RsyncFileAttributes cachedStat(Path path) throws IOException { String toStat = "unix:mode,lastModifiedTime,size,uid,gid"; Map<String, Object> attrs = Files.readAttributes(path, toStat, LinkOption.NOFOLLOW_LINKS); int mode = (int) attrs.get("mode"); long mtime = ((FileTime) attrs.get("lastModifiedTime")).to(TimeUnit.SECONDS); long size = (long) attrs.get("size"); int uid = (int) attrs.get("uid"); int gid = (int) attrs.get("gid"); String userName = _userIdToUserName.getOrDefault(uid, _defaultUser.name()); String groupName = _groupIdToGroupName.getOrDefault(gid, _defaultGroup.name()); User user = new User(userName, uid); Group group = new Group(groupName, gid); return new RsyncFileAttributes(mode, size, mtime, user, group); }
private RsyncFileAttributes fullStat(Path path) throws IOException { String toStat = "unix:mode,lastModifiedTime,size,uid,gid,owner,group"; Map<String, Object> attrs = Files.readAttributes(path, toStat, LinkOption.NOFOLLOW_LINKS); int mode = (int) attrs.get("mode"); long mtime = ((FileTime) attrs.get("lastModifiedTime")).to(TimeUnit.SECONDS); long size = (long) attrs.get("size"); int uid = (int) attrs.get("uid"); int gid = (int) attrs.get("gid"); String userName = ((UserPrincipal ) attrs.get("owner")).getName(); String groupName = ((GroupPrincipal) attrs.get("group")).getName(); User user = new User(userName, uid); Group group = new Group(groupName, gid); return new RsyncFileAttributes(mode, size, mtime, user, group); }
/** * Sets the last modification time of the entry. * * <p> When output to a ZIP file or ZIP file formatted output stream * the last modification time set by this method will be stored into * zip file entry's {@code date and time fields} in {@code standard * MS-DOS date and time format}), and the extended timestamp fields * in {@code optional extra data} in UTC time. * * @param time * The last modification time of the entry * @return This zip entry * * @throws NullPointerException if the {@code time} is null * * @see #getLastModifiedTime() * @since 1.8 */ @Substitute public ZipEntry setLastModifiedTime(FileTime time) { this.mtime = Objects.requireNonNull(time, "lastModifiedTime"); this.xdostime = javaToExtendedDosTime(time.to(TimeUnit.MILLISECONDS)); return this; }
@Override public RsyncFileAttributes stat(Path path) throws IOException { BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); return new RsyncFileAttributes(toMode(attrs), attrs.size(), attrs.lastModifiedTime().to(TimeUnit.SECONDS), _defaultUser, _defaultGroup); }
void setLastModifiedTime(SFTPPath path, FileTime lastModifiedTime, boolean followLinks) throws IOException { try (Channel channel = channelPool.get()) { if (followLinks) { path = toRealPath(channel, path, followLinks).path; } // times are in seconds channel.setMtime(path.path(), lastModifiedTime.to(TimeUnit.SECONDS)); } }
String encode(FileInfo fileInfo) { return encodePath(fileInfo.path()) + ',' + fileInfo.lastModified().to(TimeUnit.NANOSECONDS) + ',' + fileInfo.size() + ',' + fileInfo.state().name(); }
@Override public RsyncFileAttributes stat(Path path) throws IOException { PosixFileAttributes attrs = Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS); UserPrincipal userPrincipal = attrs.owner(); String userName = userPrincipal.getName(); GroupPrincipal groupPrincipal = attrs.group(); String groupName = groupPrincipal.getName(); _nameToUserPrincipal.putIfAbsent(userName, userPrincipal); _nameToGroupPrincipal.putIfAbsent(groupName, groupPrincipal); return new RsyncFileAttributes(toMode(attrs), attrs.size(), attrs.lastModifiedTime().to(TimeUnit.SECONDS), new User(userName, _defaultUserId), new Group(groupName, _defaultGroupId)); }