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


Java PosixFileAttributes.isSymbolicLink方法代碼示例

本文整理匯總了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;
}
 
開發者ID:pericles-project,項目名稱:EcoBuilder,代碼行數:33,代碼來源:MediatorScript.java

示例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;
}
 
開發者ID:ldilley,項目名稱:linulator,代碼行數:39,代碼來源:CloneFilesystem.java

示例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;
}
 
開發者ID:perlundq,項目名稱:yajsync,代碼行數:46,代碼來源:PosixFileAttributeManager.java

示例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;
}
 
開發者ID:ldilley,項目名稱:linulator,代碼行數:67,代碼來源:CloneFilesystem.java


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