Java Code Examples for java.nio.file.attribute.PosixFileAttributes#owner()
The following examples show how to use
java.nio.file.attribute.PosixFileAttributes#owner() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PosixFileAttributeManager.java From yajsync with GNU General Public License v3.0 | 6 votes |
@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)); }
Example 2
Source File: Dir.java From mdw with Apache License 2.0 | 5 votes |
private void addDetails() throws IOException { Path path = Paths.get(this.path); this.absolutePath = path.toAbsolutePath().toString().replace('\\', '/'); if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) { PosixFileAttributes attrs = Files.getFileAttributeView(path, PosixFileAttributeView.class).readAttributes(); permissions = PosixFilePermissions.toString(attrs.permissions()); UserPrincipal ownerPrincipal = attrs.owner(); owner = ownerPrincipal.toString(); UserPrincipal groupPrincipal = attrs.group(); group = groupPrincipal.toString(); size = path.toFile().length(); numLinks = path.toFile().list().length + 2; } }
Example 3
Source File: FileInfo.java From mdw with Apache License 2.0 | 5 votes |
private void addDetails() throws IOException { if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) { Path path = Paths.get(this.path); PosixFileAttributes attrs = Files.getFileAttributeView(path, PosixFileAttributeView.class).readAttributes(); permissions = PosixFilePermissions.toString(attrs.permissions()); UserPrincipal ownerPrincipal = attrs.owner(); owner = ownerPrincipal.toString(); UserPrincipal groupPrincipal = attrs.group(); group = groupPrincipal.toString(); } }