@CheckForNull private static Object getFileKey(Path path) throws IOException { BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); return attrs.fileKey(); } }
@CheckForNull private static Object getFileKey(Path path) throws IOException { BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); return attrs.fileKey(); } }
@CheckForNull private static Object getFileKey(File fileInTempDir) throws IOException { Path path = Paths.get(fileInTempDir.toURI()); BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); return attrs.fileKey(); }
/** * Create a file info for the given path. * * @param path the path must exist, otherwise an IllegalArgumentException is thrown * @return the file info object */ @NotNull public static FileInfo forPath(Path path) { try { final BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class); return FileInfo.builder() .path(path) .key(attributes.fileKey()) .size(attributes.size()) .modificationTime(attributes.lastModifiedTime()) .build(); } catch (Exception e) { LOG.error("Couldn't get file info for path: {}", path, e); return EMPTY_FILE_INFO.toBuilder().path(path).build(); } }
@Override public Object fileKey() { return host.fileKey(); }
@Override public Object fileKey() { return this.delegate.fileKey(); }
/** * Return a unique string identifying the given path object. */ public static String fileKey(final Path path) throws IOException { BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); return attrs.fileKey().toString(); }
public static String getFileKey(File file) { BasicFileAttributes basicAttr; try { basicAttr = Files.readAttributes(file.toPath(), BasicFileAttributes.class); } catch (IOException e) { return new String(); } Object obj = basicAttr.fileKey(); if (obj == null) { return new String(); } return obj.toString(); }
private String getFileKey(File file) { BasicFileAttributes basicAttr; try { basicAttr = Files.readAttributes(file.toPath(), BasicFileAttributes.class); } catch (IOException e) { return new String(); } Object obj = basicAttr.fileKey(); if (obj == null) { return new String(); } return obj.toString(); }
/** * TODO: this might not be portable as we rely on inner representation of * the {@link BasicFileAttributes#fileKey()} * ({@linkplain UnixFileKey http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/sun/nio/fs/UnixFileKey.java} * on Linux), which is not defined canonically anywhere. * @param attr * @return * @throws IOException */ public static FileId get(BasicFileAttributes attr) throws IOException { return new FileId(attr.fileKey().toString()); }
@Override public Object readAttribute(AttributeReadContext context) throws IOException { return context.getBasicFileAttributes().fileKey(); }
private boolean isSameFile( BasicFileAttributes other ) { return fileKey().equals( other.fileKey() ); }
public boolean equals(Object obj) { if (obj instanceof Key) { Key key = (Key)obj; if (!attrs.lastModifiedTime().equals(key.attrs.lastModifiedTime())) { return false; } Object fk = attrs.fileKey(); if (fk != null) { return fk.equals(key.attrs.fileKey()); } else { return file.equals(key.file); } } return false; } }
FileMetadata(File file, BasicFileAttributes attrs, String contentsHash) { this(file, attrs.creationTime(), attrs.lastModifiedTime(), attrs.fileKey(), contentsHash); }
public static String toString(BasicFileAttributes a) { StringBuilder result = new StringBuilder(); result.append("(creationTime="); result.append(a.creationTime()); result.append(",fileKey="); result.append(a.fileKey()); result.append(",isDirectory="); result.append(a.isDirectory()); result.append(",isOther="); result.append(a.isOther()); result.append(",isRegularFile="); result.append(a.isRegularFile()); result.append(",isSymbolicLink="); result.append(a.isSymbolicLink()); result.append(",lastAccessTime="); result.append(a.lastAccessTime()); result.append(",lastModifiedTime="); result.append(a.lastModifiedTime()); result.append(",size="); result.append(a.size()); result.append(")"); return result.toString(); } }
@Test @Category( { HardLink.class } ) public void testHardLinkHasSameFileKey() throws IOException { Files.createLink( link(), orig() ); Object fk1 = Files.readAttributes( orig(), BasicFileAttributes.class ).fileKey(); Object fk2 = Files.readAttributes( link(), BasicFileAttributes.class ).fileKey(); assertThat( fk1 ).isEqualTo( fk2 ); }
/** * Create a file info for the given path. * * @param path the path must exist, otherwise an IllegalArgumentException is thrown * @return the file info object */ @NotNull public static FileInfo forPath(Path path) { try { final BasicFileAttributes attributes = Files.readAttributes(path, BasicFileAttributes.class); return FileInfo.builder() .path(path) .key(attributes.fileKey()) .size(attributes.size()) .modificationTime(attributes.lastModifiedTime()) .build(); } catch (Exception e) { LOG.error("Couldn't get file info for path: {}", path, e); return EMPTY_FILE_INFO.toBuilder().path(path).build(); } }
public Builder copy(BasicFileAttributes attributes) { withCreated(attributes.creationTime().toMillis()); withLastAccessed(attributes.lastAccessTime().toMillis()); withLastModified(attributes.lastModifiedTime().toMillis()); withDirectory(attributes.isDirectory()); withOther(attributes.isOther()); withRegularFile(attributes.isRegularFile()); withSize(attributes.size()); withSymbolicLink(attributes.isSymbolicLink()); withFileKey(fromNullable(attributes.fileKey())); return this; }
public static boolean equalsIgnoreLastAccessTime(BasicFileAttributes a, BasicFileAttributes b) { if(a == b) return true; if(a == null || b == null) return false; if(!a.creationTime().equals(b.creationTime())) return false; if(!Objects.equals(a.fileKey(), b.fileKey())) return false; if(a.isDirectory() != b.isDirectory()) return false; if(a.isOther() != b.isOther()) return false; if(a.isRegularFile() != b.isRegularFile()) return false; if(a.isSymbolicLink() != b.isSymbolicLink()) return false; if(!a.lastModifiedTime().equals(b.lastModifiedTime())) return false; if(a.size() != b.size()) return false; return true; }
public static boolean equals(BasicFileAttributes a, BasicFileAttributes b) { if(a == b) return true; if(a == null || b == null) return false; if(!a.creationTime().equals(b.creationTime())) return false; if(!Objects.equals(a.fileKey(), b.fileKey())) return false; if(a.isDirectory() != b.isDirectory()) return false; if(a.isOther() != b.isOther()) return false; if(a.isRegularFile() != b.isRegularFile()) return false; if(a.isSymbolicLink() != b.isSymbolicLink()) return false; if(!a.lastAccessTime().equals(b.lastAccessTime())) return false; if(!a.lastModifiedTime().equals(b.lastModifiedTime())) return false; if(a.size() != b.size()) return false; return true; }