/** Returns whether or not the file with the given name in the given dir is a directory. */ private static boolean isDirectory( SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException { return dir.getFileAttributeView(name, BasicFileAttributeView.class, options) .readAttributes() .isDirectory(); }
/** Returns whether or not the file with the given name in the given dir is a directory. */ private static boolean isDirectory( SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException { return dir.getFileAttributeView(name, BasicFileAttributeView.class, options) .readAttributes() .isDirectory(); }
/** Returns whether or not the file with the given name in the given dir is a directory. */ private static boolean isDirectory( SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException { return dir.getFileAttributeView(name, BasicFileAttributeView.class, options) .readAttributes() .isDirectory(); }
/** * Get POSIX attributes for file. * * @param file File. * @return BasicFileAttributes. */ @Nullable public static BasicFileAttributes basicAttributes(File file) { BasicFileAttributes attrs = null; try { BasicFileAttributeView view = Files.getFileAttributeView(file.toPath(), BasicFileAttributeView.class); if (view != null) attrs = view.readAttributes(); } catch (IOException e) { throw new IgfsException("Failed to read basic file attributes: " + file.getAbsolutePath(), e); } return attrs; }
/** Returns whether or not the file with the given name in the given dir is a directory. */ private static boolean isDirectory( SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException { return dir.getFileAttributeView(name, BasicFileAttributeView.class, options) .readAttributes() .isDirectory(); }
try { 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())));
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())));
/** {@inheritDoc} */ @Override public T2<Long, Long> times(String path) throws IOException { BasicFileAttributes attrs = Files.getFileAttributeView(path(path), BasicFileAttributeView.class) .readAttributes(); return new T2<>(attrs.lastModifiedTime().toMillis(), attrs.lastAccessTime().toMillis()); }
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; }
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; }
import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.*; public class TestFA { static void getAttributes(String pathStr) throws IOException { Path p = Paths.get(pathStr); BasicFileAttributes view = Files.getFileAttributeView(p, BasicFileAttributeView.class) .readAttributes(); System.out.println(view.creationTime()+" is the same as "+view.lastModifiedTime()); } public static void main(String[] args) throws IOException { for (String s : args) { getAttributes(s); } } }
/** * @param fs * @param file * @return non null attributes object */ static Attributes getFileAttributesBasic(FS fs, File file) { try { Path nioPath = toPath(file); BasicFileAttributes readAttributes = nioPath .getFileSystem() .provider() .getFileAttributeView(nioPath, BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS).readAttributes(); Attributes attributes = new Attributes(fs, file, true, readAttributes.isDirectory(), fs.supportsExecute() ? file.canExecute() : false, readAttributes.isSymbolicLink(), readAttributes.isRegularFile(), // readAttributes.creationTime().toMillis(), // readAttributes.lastModifiedTime().toMillis(), readAttributes.isSymbolicLink() ? Constants .encode(readSymLink(file)).length : readAttributes.size()); return attributes; } catch (IOException e) { return new Attributes(file, fs); } }
@Override public <A extends BasicFileAttributes> A getReadAttributes( Class<A> read, FileAttributeView fav ) { checkViewType( fav ); checkReadType( read ); return read.cast( v( () -> viewType.cast( fav ).readAttributes() ) ); }
/** Returns whether or not the file with the given name in the given dir is a directory. */ private static boolean isDirectory( SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException { return dir.getFileAttributeView(name, BasicFileAttributeView.class, options) .readAttributes() .isDirectory(); }
/** Returns whether or not the file with the given name in the given dir is a directory. */ private static boolean isDirectory( SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException { return dir.getFileAttributeView(name, BasicFileAttributeView.class, options) .readAttributes() .isDirectory(); }
@Override public DosFileAttributes readAttributes() throws IOException { try (AutoRelease lock = this.attributes.readLock()) { BasicFileAttributeView view = this.attributes.getFileAttributeView(BasicFileAttributeView.class); return new MemoryDosFileAttributes(view.readAttributes(), this.readOnly, this.hidden, this.system, this.archive); } }
@Override public void initializeFrom(BasicFileAttributeView basicFileAttributeView) throws IOException { BasicFileAttributes otherAttributes = basicFileAttributeView.readAttributes(); this.setTimes(otherAttributes.lastModifiedTime(), otherAttributes.lastAccessTime(), otherAttributes.creationTime()); }
@Test @Category( { SymLink.class } ) public void testAttributesFromSymLinkWithFollowLinkShowNoLink_View() throws IOException { Files.createSymbolicLink( symLink(), targetFile() ); BasicFileAttributeView bfav = Files.getFileAttributeView( symLink(), BasicFileAttributeView.class ); assertThat( bfav.readAttributes().isSymbolicLink() ).isFalse(); }
@Override public PosixFileAttributes readAttributes() throws IOException { try (AutoRelease lock = this.attributes.readLock()) { BasicFileAttributeView view = this.attributes.getFileAttributeView(BasicFileAttributeView.class); return new MemoryPosixFileAttributes(view.readAttributes(), this.getOwner(), this.group, toSet(this.permissions)); } }