本文整理匯總了Java中java.nio.file.attribute.PosixFilePermissions.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java PosixFilePermissions.toString方法的具體用法?Java PosixFilePermissions.toString怎麽用?Java PosixFilePermissions.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.file.attribute.PosixFilePermissions
的用法示例。
在下文中一共展示了PosixFilePermissions.toString方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPermission
import java.nio.file.attribute.PosixFilePermissions; //導入方法依賴的package包/類
@Override
public Permission getPermission() {
if(FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
final BasicFileAttributes attributes;
try {
return new LocalPermission(PosixFilePermissions.toString(Files.readAttributes(Paths.get(path), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS).permissions()));
}
catch(IOException e) {
return Permission.EMPTY;
}
}
return Permission.EMPTY;
}
示例2: resetPosixPermissions
import java.nio.file.attribute.PosixFilePermissions; //導入方法依賴的package包/類
private boolean resetPosixPermissions(Path file, FileState fileState, PosixFileAttributes posixFileAttributes) throws IOException {
String permissions = PosixFilePermissions.toString(posixFileAttributes.permissions());
String previousPermissions = getAttribute(fileState, FileAttribute.PosixFilePermissions);
if (previousPermissions != null && !Objects.equals(permissions, previousPermissions)) {
Set<PosixFilePermission> permissionSet = PosixFilePermissions.fromString(previousPermissions);
Files.getFileAttributeView(file, PosixFileAttributeView.class).setPermissions(permissionSet);
Logger.out.printf("Set permissions: %s \t%s -> %s%n", fileState.getFileName(), permissions, previousPermissions);
return true;
}
return false;
}
示例3: compare
import java.nio.file.attribute.PosixFilePermissions; //導入方法依賴的package包/類
private void compare(TestFile file) throws KMRuntimeException, IOException {
String path = file.path;
Path realPath = file.realPath;
FileInfo fileInfo = host.getFileInfo(path);
Map<String, Object> attrs = Files.readAttributes(realPath, "*", NOFOLLOW_LINKS);
assertNotNull(fileInfo);
assertEquals(fileInfo.getPath(), path);
assertEquals(fileInfo.getGroup(), fileGroup);
assertEquals(fileInfo.getOwner(), fileUser);
if (Files.isDirectory(realPath, NOFOLLOW_LINKS)) {
assertEquals(fileInfo.getType(), DIRECTORY);
assertNull(fileInfo.getLinkTarget());
} else if (Files.isRegularFile(realPath, NOFOLLOW_LINKS)) {
assertEquals(fileInfo.getType(), FILE);
assertNull(fileInfo.getLinkTarget());
assertEquals(fileInfo.getSize(), Files.size(realPath));
} else if (Files.isSymbolicLink(realPath)) {
assertEquals(fileInfo.getType(), SYMLINK);
assertEquals(fileInfo.getLinkTarget(), file.target);
} else {
assertEquals(fileInfo.getType(), OTHER);
assertNull(fileInfo.getLinkTarget());
}
String expectedPerms = PosixFilePermissions.toString(Files.getPosixFilePermissions(realPath, NOFOLLOW_LINKS));
if (host instanceof SshHost) {
expectedPerms = (fileInfo.getType() == DIRECTORY ? "d" : "-") + expectedPerms;
}
assertEquals(fileInfo.getPermissions(), expectedPerms);
assertEquals(fileInfo.getModified(), ((FileTime) attrs.get("lastModifiedTime")).toMillis());
}
示例4: getPermissions
import java.nio.file.attribute.PosixFilePermissions; //導入方法依賴的package包/類
@Override
public String getPermissions() throws IOException {
return PosixFilePermissions.toString(Files.getPosixFilePermissions(file.toPath()));
}
示例5: getPermissions
import java.nio.file.attribute.PosixFilePermissions; //導入方法依賴的package包/類
public String getPermissions(Path path) {
return PosixFilePermissions.toString(getAttributes(path).permissions());
}
示例6: preVisitDirectory
import java.nio.file.attribute.PosixFilePermissions; //導入方法依賴的package包/類
@Override public FileVisitResult preVisitDirectory(Path directory, BasicFileAttributes basicAttribs) throws IOException
{
boolean skip = false;
for(int i = 0; i < excludes.size(); i++)
{
if(directory.toString().matches(excludes.get(i)))
skip = true;
}
if(skip)
{
System.out.println("Ignored excluded directory: " + directory);
return FileVisitResult.CONTINUE;
}
if(pathExists(directory))
{
System.out.println("Skipping existing directory: " + directory);
return FileVisitResult.CONTINUE;
}
System.out.print("Importing directory: " + directory);
PosixFileAttributes posixAttribs = Files.readAttributes(directory, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
SimpleDateFormat timestampFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date currentTime = new Date();
String timestamp = timestampFormat.format(currentTime);
System.out.println(" " + timestamp);
Set<PosixFilePermission> posixPerms = posixAttribs.permissions();
String perms = PosixFilePermissions.toString(posixPerms);
String inode = posixAttribs.fileKey().toString();
Pattern p = Pattern.compile("\\=(\\d+)\\)");
Matcher m = p.matcher(inode);
m.find();
inode = m.group(1);
long mtimeStamp = posixAttribs.lastModifiedTime().toMillis();
if(posixAttribs.isSymbolicLink())
System.out.println(Files.readSymbolicLink(directory).toString());
// Log this to file once in production
//System.out.println("Properties of directory: " + directory);
//System.out.println(inode + " " + perms + " " + posixAttribs.owner().getName() + ":" + posixAttribs.group().getName() + " " + posixAttribs.size() + " " + calcMtime(mtimeStamp) + "\n");
CloneFilesystem.Record entry = new CloneFilesystem.Record();
entry.path = directory.toString();
entry.name = new File(entry.path).getName();
entry.inode = Long.parseLong(inode);
entry.type = determineType(directory, posixAttribs);
entry.mode = calculateOctalPerms(perms);
entry.linkCount = 1; // link count is currently broken; set a default of one (itself)
entry.uid = users.get(posixAttribs.owner().getName()); // use containsKey() if this causes a null pointer exception
entry.gid = groups.get(posixAttribs.group().getName()); // same as above
entry.atime = posixAttribs.lastAccessTime().toMillis();
entry.ctime = posixAttribs.creationTime().toMillis();
entry.mtime = posixAttribs.lastModifiedTime().toMillis();
if(posixAttribs.isSymbolicLink())
entry.link = Files.readSymbolicLink(directory).toString();
else
entry.link = null;
entry.data = "";
writeDatabase(entry, false, true);
return FileVisitResult.CONTINUE;
}