本文整理汇总了Java中java.nio.file.attribute.PosixFileAttributes.isSymbolicLink方法的典型用法代码示例。如果您正苦于以下问题:Java PosixFileAttributes.isSymbolicLink方法的具体用法?Java PosixFileAttributes.isSymbolicLink怎么用?Java PosixFileAttributes.isSymbolicLink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.attribute.PosixFileAttributes
的用法示例。
在下文中一共展示了PosixFileAttributes.isSymbolicLink方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConcreteReport
import java.nio.file.attribute.PosixFileAttributes; //导入方法依赖的package包/类
public ReportFile createConcreteReport(String identifier, Path path) {
ReportFile file = createEntity(scenario, identifier);
PosixFileAttributes posixAttributes = null;
try {
posixAttributes = Files.readAttributes(path, PosixFileAttributes.class);
} catch (IOException e) {
System.err.println("The mediator script example won't work correctly on your machine due to missing privileges.");
return file;
}
String type = "other";
if (posixAttributes.isRegularFile()) {
type = "regular_file";
} else if (posixAttributes.isDirectory()) {
type = "directory";
} else if (posixAttributes.isSymbolicLink()) {
type = "symbolic_link";
}
String modified = posixAttributes.lastModifiedTime().toString();
String access = posixAttributes.lastAccessTime().toString();
String time = posixAttributes.creationTime().toString();
String size = "" + posixAttributes.size();
String key = posixAttributes.fileKey().toString();
String groupOwner = posixAttributes.group().getName();
file.addProperty(lastModified, modified);
file.addProperty(lastAccess, access);
file.addProperty(creationTime, time);
file.addProperty(fileType, type);
file.addProperty(fileSize, size);
file.addProperty(fileKey, key);
file.addProperty(fileGroupOwner, groupOwner);
return file;
}
示例2: determineType
import java.nio.file.attribute.PosixFileAttributes; //导入方法依赖的package包/类
public static byte determineType(Path file, PosixFileAttributes posixAttribs)
{
byte type = 5;
if(posixAttribs.isRegularFile())
type = 5;
else if(posixAttribs.isDirectory())
type = 2;
else if(posixAttribs.isSymbolicLink())
type = 4;
else if(posixAttribs.isOther())
{
try
{
Process process = new ProcessBuilder("/bin/ls", "-la", file.toString()).start();
InputStream inputStream = process.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line = null;
line = bufferedReader.readLine();
if(line.charAt(0) == 'b')
type = 0; // block
else if(line.charAt(0) == 'c')
type = 1; // character
else if(line.charAt(0) == 'p')
type = 3; // pipe/FIFO
else if(line.charAt(0) == 's')
type = 6; // socket
}
catch(IOException ioe)
{
System.err.println("Unable to run process to determine file type.");
System.err.println(ioe.getMessage());
}
}
return type;
}
示例3: toMode
import java.nio.file.attribute.PosixFileAttributes; //导入方法依赖的package包/类
private static int toMode(PosixFileAttributes attrs)
{
int mode = 0;
if (attrs.isDirectory()) {
mode |= FileOps.S_IFDIR;
} else if (attrs.isRegularFile()) {
mode |= FileOps.S_IFREG;
} else if (attrs.isSymbolicLink()) {
mode |= FileOps.S_IFLNK;
} else {
mode |= FileOps.S_IFUNK;
}
Set<PosixFilePermission> perms = attrs.permissions();
if (perms.contains(PosixFilePermission.OWNER_READ)) {
mode |= FileOps.S_IRUSR;
}
if (perms.contains(PosixFilePermission.OWNER_WRITE)) {
mode |= FileOps.S_IWUSR;
}
if (perms.contains(PosixFilePermission.OWNER_EXECUTE)) {
mode |= FileOps.S_IXUSR;
}
if (perms.contains(PosixFilePermission.GROUP_READ)) {
mode |= FileOps.S_IRGRP;
}
if (perms.contains(PosixFilePermission.GROUP_WRITE)) {
mode |= FileOps.S_IWGRP;
}
if (perms.contains(PosixFilePermission.GROUP_EXECUTE)) {
mode |= FileOps.S_IXGRP;
}
if (perms.contains(PosixFilePermission.OTHERS_READ)) {
mode |= FileOps.S_IROTH;
}
if (perms.contains(PosixFilePermission.OTHERS_WRITE)) {
mode |= FileOps.S_IWOTH;
}
if (perms.contains(PosixFilePermission.OTHERS_EXECUTE)) {
mode |= FileOps.S_IXOTH;
}
return mode;
}
示例4: preVisitDirectory
import java.nio.file.attribute.PosixFileAttributes; //导入方法依赖的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;
}