Example usage for java.nio.file.attribute AclEntry newBuilder

List of usage examples for java.nio.file.attribute AclEntry newBuilder

Introduction

In this page you can find the example usage for java.nio.file.attribute AclEntry newBuilder.

Prototype

public static Builder newBuilder() 

Source Link

Document

Constructs a new builder.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Path path = Paths.get("C:\\Java_Dev\\test1.txt");

    AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class);
    if (aclView == null) {
        System.out.format("ACL view  is not  supported.%n");
        return;/* w w  w .jav  a2  s. c o  m*/
    }
    UserPrincipal bRiceUser = FileSystems.getDefault().getUserPrincipalLookupService()
            .lookupPrincipalByName("brice");

    Set<AclEntryPermission> permissions = EnumSet.of(AclEntryPermission.READ_DATA,
            AclEntryPermission.WRITE_DATA);

    AclEntry.Builder builder = AclEntry.newBuilder();
    builder.setPrincipal(bRiceUser);
    builder.setType(AclEntryType.ALLOW);
    builder.setPermissions(permissions);
    AclEntry newEntry = builder.build();

    List<AclEntry> aclEntries = aclView.getAcl();

    aclEntries.add(newEntry);

    aclView.setAcl(aclEntries);
}