Here are the examples of the java api class java.nio.file.attribute.AclFileAttributeView taken from open source projects.
1. AclAttributeProviderTest#testView()
Project: jimfs
File: AclAttributeProviderTest.java
File: AclAttributeProviderTest.java
@Test public void testView() throws IOException { AclFileAttributeView view = provider.view(fileLookup(), ImmutableMap.<String, FileAttributeView>of("owner", new OwnerAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS))); assertNotNull(view); assertThat(view.name()).isEqualTo("acl"); assertThat(view.getAcl()).isEqualTo(defaultAcl); view.setAcl(ImmutableList.<AclEntry>of()); view.setOwner(FOO); assertThat(view.getAcl()).isEqualTo(ImmutableList.<AclEntry>of()); assertThat(view.getOwner()).isEqualTo(FOO); assertThat(file.getAttribute("acl", "acl")).isEqualTo(ImmutableList.<AclEntry>of()); }
2. SftpSubsystem#setFileAccessControl()
Project: mina-sshd
File: SftpSubsystem.java
File: SftpSubsystem.java
protected void setFileAccessControl(Path file, List<AclEntry> acl, LinkOption... options) throws IOException { AclFileAttributeView view = Files.getFileAttributeView(file, AclFileAttributeView.class, options); if (view == null) { throw new UnsupportedOperationException("ACL view not supported for " + file); } if (log.isTraceEnabled()) { log.trace("setFileAccessControl({})[{}] {}", getServerSession(), file, acl); } view.setAcl(acl); }
3. FileUtil#limitAccessToOwnerViaFileAttributeView()
Project: derby
File: FileUtil.java
File: FileUtil.java
/** * Limit access to owner using a * {@code java.nio.file.attribute.FileAttributeView}. * Such views are only available on Java 7 and higher, and only on * file systems that support changing file permissions. Currently, * this is supported on POSIX file systems and file systems that * maintain access control lists (ACLs). * * @param file the file to limit access to * @return {@code true} on success, or {@code false} if some of the * permissions could not be changed */ private static boolean limitAccessToOwnerViaFileAttributeView(File file) throws IOException { Path fileP = file.toPath(); PosixFileAttributeView posixView = Files.getFileAttributeView(fileP, PosixFileAttributeView.class); if (posixView != null) { // This is a POSIX file system. Usually, // FileUtil.limitAccessToOwnerViaFile() will successfully set // the permissions on such file systems using the java.io.File // class, so we don't get here. If, however, that approach failed, // we try again here using a PosixFileAttributeView. That's likely // to fail too, but at least now we will get an IOException that // explains why it failed. EnumSet<PosixFilePermission> perms = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE); if (file.isDirectory()) { perms.add(PosixFilePermission.OWNER_EXECUTE); } posixView.setPermissions(perms); return true; } AclFileAttributeView aclView = Files.getFileAttributeView(fileP, AclFileAttributeView.class); if (aclView != null) { // Since we have an AclFileAttributeView which is not a // PosixFileAttributeView, we probably have an NTFS file // system. // Remove existing ACEs, build a new one which simply // gives all possible permissions to current owner. AclEntry ace = AclEntry.newBuilder().setPrincipal(Files.getOwner(fileP)).setType(AclEntryType.ALLOW).setPermissions(EnumSet.allOf(AclEntryPermission.class)).build(); aclView.setAcl(Collections.singletonList(ace)); return true; } // We don't know how to set permissions on this file system. return false; }