當前位置: 首頁>>代碼示例>>Java>>正文


Java UserPrincipal.getName方法代碼示例

本文整理匯總了Java中java.nio.file.attribute.UserPrincipal.getName方法的典型用法代碼示例。如果您正苦於以下問題:Java UserPrincipal.getName方法的具體用法?Java UserPrincipal.getName怎麽用?Java UserPrincipal.getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.file.attribute.UserPrincipal的用法示例。


在下文中一共展示了UserPrincipal.getName方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getOwnerName

import java.nio.file.attribute.UserPrincipal; //導入方法依賴的package包/類
private String getOwnerName(File file)
{
	String directory = file.getAbsolutePath();
	Path path = Paths.get(directory);
	FileOwnerAttributeView ownerAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
	UserPrincipal owner = null;

	try
	{
		owner = ownerAttributeView.getOwner();
	} catch (IOException e)
	{
		throw new PersonifilerException(e);
	}

	return owner.getName();
}
 
開發者ID:allen12,項目名稱:Personifiler,代碼行數:18,代碼來源:FileSystemWriter.java

示例2: stat

import java.nio.file.attribute.UserPrincipal; //導入方法依賴的package包/類
@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));
}
 
開發者ID:perlundq,項目名稱:yajsync,代碼行數:18,代碼來源:PosixFileAttributeManager.java

示例3: getOwner

import java.nio.file.attribute.UserPrincipal; //導入方法依賴的package包/類
/**
 *
 * @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 );
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:20,代碼來源:LocalFileSystemOperations.java

示例4: getOwner

import java.nio.file.attribute.UserPrincipal; //導入方法依賴的package包/類
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();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:CheckLockLocationTest.java

示例5: readStatAndOwner

import java.nio.file.attribute.UserPrincipal; //導入方法依賴的package包/類
public ProcessStatAndOwner readStatAndOwner(int pid) {
    try {
        ProcessStat processStat;
        File        statFile;
        UserPrincipal   owner;
        
        statFile = new File(proc +"/"+ pid +"/stat");
        processStat = reader.read(statFile);
        owner = Files.getOwner(Paths.get(statFile.getAbsolutePath()));
        return new ProcessStatAndOwner(processStat, owner.getName());
    } catch (IOException ioe) {
        return null;
    }
}
 
開發者ID:Morgan-Stanley,項目名稱:SilverKing,代碼行數:15,代碼來源:ProcReader.java


注:本文中的java.nio.file.attribute.UserPrincipal.getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。