当前位置: 首页>>代码示例>>Java>>正文


Java Files.isSymbolicLink方法代码示例

本文整理汇总了Java中java.nio.file.Files.isSymbolicLink方法的典型用法代码示例。如果您正苦于以下问题:Java Files.isSymbolicLink方法的具体用法?Java Files.isSymbolicLink怎么用?Java Files.isSymbolicLink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.isSymbolicLink方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: describeFile

import java.nio.file.Files; //导入方法依赖的package包/类
private static void describeFile(
    final Path workspaceDirectory, final Path path, final PrintWriter out) {
  final Path relativeFileName = workspaceDirectory.relativize(path);
  if (Files.isDirectory(path)) {
    // Do nothing
  } else if (Files.isSymbolicLink(path)) {
    out.printf("link\t%s\t%s\t%s\n", Strings.repeat("-", 32), relativeFileName, readLink(path));
  } else if (Files.isRegularFile(path)) {
    final HashCode sha256;

    try {
      sha256 = PathUtils.sha256(path);
    } catch (IOException e) {
      throw new UncheckedIOException("Could not compute sha256 of " + path, e);
    }

    out.printf("file\t%s\t%s\n", sha256, relativeFileName);
  } else {
    throw new IllegalStateException("Path " + path + " is an unsupported type");
  }
}
 
开发者ID:spotify,项目名称:bazel-tools,代码行数:22,代码来源:Main.java

示例2: validateMount

import java.nio.file.Files; //导入方法依赖的package包/类
@VisibleForTesting
protected String validateMount(String mount,
    Map<Path, List<String>> localizedResources)
    throws ContainerExecutionException {
  for (Entry<Path, List<String>> resource : localizedResources.entrySet()) {
    if (resource.getValue().contains(mount)) {
      java.nio.file.Path path = Paths.get(resource.getKey().toString());
      if (!path.isAbsolute()) {
        throw new ContainerExecutionException("Mount must be absolute: " +
                mount);
      }
      if (Files.isSymbolicLink(path)) {
        throw new ContainerExecutionException("Mount cannot be a symlink: " +
                mount);
      }
      if (isArbitraryMount(mount)) {
        throw new ContainerExecutionException("Mount is not allowed in the white list");
      }
      return path.toString();
    }
  }
  throw new ContainerExecutionException("Mount must be a localized " +
      "resource: " + mount);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:DockerLinuxContainerRuntime.java

示例3: countFiles

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * 
 * @param dir
 * @return
 * @throws IOException
 */
public static int countFiles(Path dir) throws IOException {
    int c = 0;
    if (Files.isDirectory(dir)) {
        try (DirectoryStream<Path> files = Files.newDirectoryStream(dir)) {
            for (Path file : files) {
                if (Files.isRegularFile(file) || Files.isSymbolicLink(file)) {
                    c++;
                }
            }
        }
    }

    return c;
}
 
开发者ID:intranda,项目名称:goobi-viewer-indexer,代码行数:21,代码来源:DataRepository.java

示例4: verifySymLinks

import java.nio.file.Files; //导入方法依赖的package包/类
private void verifySymLinks(String bindir) throws IOException {
    File binDir = new File(bindir);
    System.err.println("verifying links in: " + bindir);
    File isaDir = new File(binDir, getArch()).getAbsoluteFile();
    if (!isaDir.exists()) {
        throw new RuntimeException("dir: " + isaDir + " does not exist");
    }
    try (DirectoryStream<Path> ds = Files.newDirectoryStream(binDir.toPath())) {
        for (Path p : ds) {
            if (symlinkExcludes.matcher(p.toString()).matches() ||
                    Files.isDirectory(p, NOFOLLOW_LINKS)) {
                continue;
            }
            Path link = new File(isaDir, p.getFileName().toString()).toPath();
            if (Files.isSymbolicLink(link)) {
                Path target = Files.readSymbolicLink(link);
                if (target.startsWith("..") && p.endsWith(target.getFileName())) {
                    // System.out.println(target + " OK");
                    continue;
                }
                System.err.println("target:" + target);
                System.err.println("file:" + p);
            }
            throw new RuntimeException("could not find link to " + p);
        }
    }

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:ExecutionEnvironment.java

示例5: deleteSymlinks

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Recursively delete all symlinks in a directory.
 */
private void deleteSymlinks(File root) {
    for (File f : root.listFiles()) {
        if (Files.isSymbolicLink(f.toPath())) {
            f.delete();
        } else if (f.isDirectory()) {
            deleteSymlinks(f);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:FileObjSymlinkTest.java

示例6: deleteFile

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Recursively delete directory, do not throw an exception if a file cannot
 * be deleted, do not traverse symbolic links.
 */
private static void deleteFile(File file) throws IOException {
    if (file.isDirectory() && file.equals(file.getCanonicalFile())
            && !Files.isSymbolicLink(file.toPath())) {
        // file is a directory - delete sub files first
        File files[] = file.listFiles();
        for (File file1 : files) {
            deleteFile(file1);
        }
    }
    // file is a File :-)
    file.delete();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:FileObjectCyclicSymlinksTest.java

示例7: getSymbolicLinkTargetFile

import java.nio.file.Files; //导入方法依赖的package包/类
public static Path getSymbolicLinkTargetFile(Path path) {
    if (!Files.isSymbolicLink(path)) {
        return path;
    }

    try {
        Path targetPath = Files.readSymbolicLink(path);
        return getSymbolicLinkTargetFile(targetPath);
    } catch (IOException e) {
        throw new RuntimeException("Failed to read symbolic link: " + path, e);
    }
}
 
开发者ID:uber,项目名称:uberscriptquery,代码行数:13,代码来源:FileUtils.java

示例8: list

import java.nio.file.Files; //导入方法依赖的package包/类
public static List<ProcOpenFile> list() throws FileNotFoundException {
    final String jvmName = ManagementFactory.getRuntimeMXBean().getName();
    final int index = jvmName.indexOf('@');
    String pid = (jvmName.substring(0, index));

    List<ProcOpenFile> rtn = new ArrayList<>();

    File folder = new File("/proc/" + pid + "/fd");
    if(folder.isDirectory()){
        File[] files = folder.listFiles();
        if(files == null){
            return rtn;
        }
        for(File fd:files){
            Path path = fd.toPath();
            if(Files.isSymbolicLink(path)){
                try {
                    File real = Files.readSymbolicLink(path).toFile();
                    if(real.isFile()) {
                        ProcOpenFile of = new ProcOpenFile();
                        of.name = real.getName();
                        of.size = real.length();
                        of.path = real.getAbsolutePath();
                        rtn.add(of);
                    }
                } catch (Throwable e) {
                    logger.warn("Read link:"+path.toString()+" failed!");
                }
            }
        }
    }
    return rtn;
}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:34,代码来源:ProcOpenFile.java

示例9: isExcluded

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Returns whether the given file is excluded.
 *
 * @param file The child file in question.
 * @return Whether the child file is excluded.
 */
private boolean isExcluded(File file) {
    if (settingsService.getIgnoreSymLinks() && Files.isSymbolicLink(file.toPath())) {
        LOG.info("excluding symbolic link " + file.toPath());
        return true;
    }
    String name = file.getName();
    if (settingsService.getExcludePattern() != null && settingsService.getExcludePattern().matcher(name).find()) {
        LOG.info("excluding file which matches exclude pattern " + settingsService.getExcludePatternString() + ": " + file.toPath());
        return true;
    }

    // Exclude all hidden files starting with a single "." or "@eaDir" (thumbnail dir created on Synology devices).
    return (name.startsWith(".") && !name.startsWith("..")) || name.startsWith("@eaDir") || name.equals("Thumbs.db");
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:21,代码来源:MediaFileService.java

示例10: toFileName

import java.nio.file.Files; //导入方法依赖的package包/类
public static String toFileName(String path) throws IOException {
  File f = new File(path);
  String fileName = f.getName();
  if(Files.isSymbolicLink(f.toPath())) {
    Path p = Files.readSymbolicLink(f.toPath());
    fileName = p.getFileName().toFile().getName();
  }
  return fileName;
}
 
开发者ID:simonellistonball,项目名称:metron-field-demos,代码行数:10,代码来源:DemoLoader.java

示例11: isSymbolicLink

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Returns true if the specified file is a symbolic link, and also logs a warning if it is.
 * @param file the file
 * @return true if file is a symbolic link, false otherwise.
 */
private static boolean isSymbolicLink(final File file) {
    if (Files.isSymbolicLink(file.toPath())) {
        getLogger().warning("Directory " + file + " is a symlink");
        return true;
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:OptimisticTypesPersistence.java

示例12: getPackagePath

import java.nio.file.Files; //导入方法依赖的package包/类
synchronized Path getPackagePath(String pkgName) throws IOException {
    // check the cache first
    if (pkgDirs.containsKey(pkgName)) {
        return pkgDirs.get(pkgName);
    }

    Path pkgLink = fs.getPath("/packages/" + pkgName.replace('/', '.'));
    // check if /packages/$PACKAGE directory exists
    if (Files.isDirectory(pkgLink)) {
       try (DirectoryStream<Path> stream = Files.newDirectoryStream(pkgLink)) {
            for (Path p : stream) {
                // find first symbolic link to module directory
                if (Files.isSymbolicLink(p)) {
                    Path modDir = Files.readSymbolicLink(p);
                    if (Files.isDirectory(modDir)) {
                        // get package subdirectory under /modules/$MODULE/
                        Path pkgDir = fs.getPath(modDir.toString() + "/" + pkgName);
                        if (Files.isDirectory(pkgDir)) {
                            // it is a package directory only if contains
                            // at least one .class file
                            try (DirectoryStream<Path> pstream =
                                    Files.newDirectoryStream(pkgDir)) {
                                for (Path f : pstream) {
                                    if (Files.isRegularFile(f)
                                            && f.toString().endsWith(".class")) {
                                        pkgDirs.put(pkgName, pkgDir);
                                        return pkgDir;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:ClassPath.java

示例13: loadAndCheck

import java.nio.file.Files; //导入方法依赖的package包/类
private int loadAndCheck(Path p, AuthTimeWithHash time,
        KerberosTime currTime)
        throws IOException, KrbApErrException {
    int missed = 0;
    if (Files.isSymbolicLink(p)) {
        throw new IOException("Symlink not accepted");
    }
    try {
        Set<PosixFilePermission> perms =
                Files.getPosixFilePermissions(p);
        if (uid != -1 &&
                (Integer)Files.getAttribute(p, "unix:uid") != uid) {
            throw new IOException("Not mine");
        }
        if (perms.contains(PosixFilePermission.GROUP_READ) ||
                perms.contains(PosixFilePermission.GROUP_WRITE) ||
                perms.contains(PosixFilePermission.GROUP_EXECUTE) ||
                perms.contains(PosixFilePermission.OTHERS_READ) ||
                perms.contains(PosixFilePermission.OTHERS_WRITE) ||
                perms.contains(PosixFilePermission.OTHERS_EXECUTE)) {
            throw new IOException("Accessible by someone else");
        }
    } catch (UnsupportedOperationException uoe) {
        // No POSIX permissions? Ignore it.
    }
    chan = Files.newByteChannel(p, StandardOpenOption.WRITE,
            StandardOpenOption.READ);

    long timeLimit = currTime.getSeconds() - readHeader(chan);

    long pos = 0;
    boolean seeNewButNotSame = false;
    while (true) {
        try {
            pos = chan.position();
            AuthTime a = AuthTime.readFrom(chan);
            if (a instanceof AuthTimeWithHash) {
                if (time.equals(a)) {
                    // Exact match, must be a replay
                    throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                } else if (time.sameTimeDiffHash((AuthTimeWithHash)a)) {
                    // Two different authenticators in the same second.
                    // Remember it
                    seeNewButNotSame = true;
                }
            } else {
                if (time.isSameIgnoresHash(a)) {
                    // Two authenticators in the same second. Considered
                    // same if we haven't seen a new style version of it
                    if (!seeNewButNotSame) {
                        throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                    }
                }
            }
            if (a.ctime < timeLimit) {
                missed++;
            } else {
                missed--;
            }
        } catch (BufferUnderflowException e) {
            // Half-written file?
            chan.position(pos);
            break;
        }
    }
    return missed;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:68,代码来源:DflCache.java

示例14: init

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public void init() {
    resetDbLock.writeLock().lock();
    try {
        logger.debug("~> LevelDbDataSource.init(): " + name);

        if (isAlive()) return;

        if (name == null) throw new NullPointerException("no name set to the db");

        Options options = new Options();
        options.createIfMissing(true);
        options.compressionType(CompressionType.NONE);
        options.blockSize(10 * 1024 * 1024);
        options.writeBufferSize(10 * 1024 * 1024);
        options.cacheSize(0);
        options.paranoidChecks(true);
        options.verifyChecksums(true);
        options.maxOpenFiles(32);

        try {
            logger.debug("Opening database");
            final Path dbPath = getPath();
            if (!Files.isSymbolicLink(dbPath.getParent())) Files.createDirectories(dbPath.getParent());

            logger.debug("Initializing new or existing database: '{}'", name);
            try {
                db = factory.open(dbPath.toFile(), options);
            } catch (IOException e) {
                // database could be corrupted
                // exception in std out may look:
                // org.fusesource.leveldbjni.internal.NativeDB$DBException: Corruption: 16 missing files; e.g.: /Users/stan/ethereumj/database-test/block/000026.ldb
                // org.fusesource.leveldbjni.internal.NativeDB$DBException: Corruption: checksum mismatch
                if (e.getMessage().contains("Corruption:")) {
                    logger.warn("Problem initializing database.", e);
                    logger.info("LevelDB database must be corrupted. Trying to repair. Could take some time.");
                    factory.repair(dbPath.toFile(), options);
                    logger.info("Repair finished. Opening database again.");
                    db = factory.open(dbPath.toFile(), options);
                } else {
                    // must be db lock
                    // org.fusesource.leveldbjni.internal.NativeDB$DBException: IO error: lock /Users/stan/ethereumj/database-test/state/LOCK: Resource temporarily unavailable
                    throw e;
                }
            }

            alive = true;
        } catch (IOException ioe) {
            logger.error(ioe.getMessage(), ioe);
            throw new RuntimeException("Can't initialize database", ioe);
        }
        logger.debug("<~ LevelDbDataSource.init(): " + name);
    } finally {
        resetDbLock.writeLock().unlock();
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:57,代码来源:LevelDbDataSource.java

示例15: isSymbolicLink

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public boolean isSymbolicLink() throws IOException {
    Path p = getNativePath();
    return Files.isSymbolicLink(p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:BaseFileObj.java


注:本文中的java.nio.file.Files.isSymbolicLink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。