Java Code Examples for java.nio.file.attribute.UserPrincipal#getName()

The following examples show how to use java.nio.file.attribute.UserPrincipal#getName() . 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 vote down vote up
@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: CheckLockLocationTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: CheckLockLocationTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 4
Source File: CheckLockLocationTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 5
Source File: CheckLockLocationTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 6
Source File: CheckLockLocationTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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 7
Source File: CheckLockLocationTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: CheckLockLocationTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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 9
Source File: CheckLockLocationTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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 10
Source File: CheckLockLocationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 11
Source File: CheckLockLocationTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 12
Source File: LocalFileSystemOperations.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param filename the file name
 * @return the file owner
 * @throws FileSystemOperationException
 */
private String getOwner(
        String filename ) {

    try {
        UserPrincipal owner = Files.readAttributes(new File(filename).toPath(),
                                                   PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS)
                                   .owner();
        return owner.getName();

    } catch (Exception e) {
        throw new FileSystemOperationException("Could not get owner for '" + filename + "'", e);
    }
}
 
Example 13
Source File: CheckLockLocationTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 14
Source File: CWLParser.java    From cwlexec with Apache License 2.0 5 votes vote down vote up
private static String getFileOwner(File file) {
    String owner = null;
    if (file != null) {
        Path path = Paths.get(file.getAbsolutePath());
        try {
            UserPrincipal user = Files.getFileAttributeView(path, FileOwnerAttributeView.class).getOwner();
            return user.getName();
        } catch (IOException e) {
            logger.warn("Fail to get the owner of {}, ({})", path, e.getMessage());
        }
    }
    return owner;
}
 
Example 15
Source File: CheckLockLocationTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 16
Source File: CheckLockLocationTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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 17
Source File: UnixSshFileSystemProvider.java    From jsch-nio with MIT License 4 votes vote down vote up
void setOwner( UnixSshPath path, UserPrincipal owner ) throws IOException {
    String command = path.getFileSystem().getCommand( "chown" )
            + " " + owner.getName() + " " + path.toAbsolutePath().quotedString();
    executeForStdout( path, command );
}