Java Code Examples for java.nio.file.Files.getOwner()

The following are Jave code examples for showing how to use getOwner() of the java.nio.file.Files class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: TestVMOptionsFile.java   View Source Code Vote up 6 votes
private static void makeFileNonReadable(String file) throws IOException {
    Path filePath = Paths.get(file);
    Set<String> supportedAttr = filePath.getFileSystem().supportedFileAttributeViews();

    if (supportedAttr.contains("posix")) {
        Files.setPosixFilePermissions(filePath, PosixFilePermissions.fromString("-w--w----"));
    } else if (supportedAttr.contains("acl")) {
        UserPrincipal fileOwner = Files.getOwner(filePath);

        AclFileAttributeView view = Files.getFileAttributeView(filePath, AclFileAttributeView.class);

        AclEntry entry = AclEntry.newBuilder()
                .setType(AclEntryType.DENY)
                .setPrincipal(fileOwner)
                .setPermissions(AclEntryPermission.READ_DATA)
                .build();

        List<AclEntry> acl = view.getAcl();
        acl.add(0, entry);
        view.setAcl(acl);
    }
}
 
Example 2
Project: jdk8u-jdk   File: CheckLockLocationTest.java   View Source Code Vote up 5 votes
private static String getOwner(Path path) {
    UserPrincipal user = null;
    try {
        user = Files.getOwner(path);
    } catch (Exception x) {
        System.err.println("Failed to get owner of: " + path);
        System.err.println("\terror is: " + x);
    }
    return user == null ? "???" : user.getName();
}
 
Example 3
Project: openjdk-jdk10   File: CheckLockLocationTest.java   View Source Code Vote up 5 votes
private static String getOwner(Path path) {
    UserPrincipal user = null;
    try {
        user = Files.getOwner(path);
    } catch (Exception x) {
        System.err.println("Failed to get owner of: " + path);
        System.err.println("\terror is: " + x);
    }
    return user == null ? "???" : user.getName();
}