本文整理匯總了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();
}
示例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));
}
示例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 );
}
}
示例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();
}
示例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;
}
}