java.nio.file.Files.isSymbolicLink()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(216)

本文整理了Java中java.nio.file.Files.isSymbolicLink()方法的一些代码示例,展示了Files.isSymbolicLink()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.isSymbolicLink()方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:isSymbolicLink

Files.isSymbolicLink介绍

暂无

代码示例

代码示例来源:origin: org.assertj/assertj-core

public boolean isSymbolicLink(Path path) {
 return Files.isSymbolicLink(path);
}

代码示例来源:origin: SonarSource/sonarqube

public CleanDirectoryFileVisitor(Path path) {
 this.path = path;
 this.symLink = Files.isSymbolicLink(path);
}

代码示例来源:origin: SonarSource/sonarqube

private CleanDirectoryFileVisitor(Path path) {
 this.path = path;
 this.symLink = Files.isSymbolicLink(path);
}

代码示例来源:origin: SonarSource/sonarqube

CleanTempDirFileVisitor(Path path) {
 this.path = path;
 this.symLink = Files.isSymbolicLink(path);
}

代码示例来源:origin: looly/hutool

/**
   * 判断是否为符号链接文件
   * 
   * @param file 被检查的文件
   * @return 是否为符号链接文件
   * @since 4.4.2
   */
  public static boolean isSymlink(File file) throws IORuntimeException {
    return Files.isSymbolicLink(file.toPath());
  }
}

代码示例来源:origin: looly/hutool

/**
   * 判断是否为符号链接文件
   * 
   * @param file 被检查的文件
   * @return 是否为符号链接文件
   * @since 4.4.2
   */
  public static boolean isSymlink(File file) throws IORuntimeException {
    return Files.isSymbolicLink(file.toPath());
  }
}

代码示例来源:origin: org.codehaus.plexus/plexus-utils

public static boolean isSymbolicLink( File file )
{
  return Files.isSymbolicLink( file.toPath() );
}

代码示例来源:origin: oracle/helidon

private Path target(Path path) throws IOException {
  Path target = path;
  while (Files.isSymbolicLink(target)) {
    target = target.toRealPath();
  }
  return target;
}

代码示例来源:origin: oblac/jodd

/**
 * Determines whether the specified file is a symbolic link rather than an actual file.
 *
 * @deprecated {@link java.nio.file.Files#isSymbolicLink(java.nio.file.Path)} provides this functionality natively as of Java 1.7.
 */
@Deprecated
public static boolean isSymlink(final File file) {
  return Files.isSymbolicLink(file.toPath());
}

代码示例来源:origin: commons-io/commons-io

/**
   * Determines whether the specified file is a Symbolic Link rather than an actual file.
   * <p>
   * Will not return true if there is a Symbolic Link anywhere in the path,
   * only if the specific file is.
   * <p>
   * When using jdk1.7, this method delegates to {@code boolean java.nio.file.Files.isSymbolicLink(Path path)}
   *
   * <b>Note:</b> the current implementation always returns {@code false} if running on
   * jkd1.6 and the system is detected as Windows using {@link FilenameUtils#isSystemWindows()}
   * <p>
   * For code that runs on Java 1.7 or later, use the following method instead:
   * <br>
   * {@code boolean java.nio.file.Files.isSymbolicLink(Path path)}
   * @param file the file to check
   * @return true if the file is a Symbolic Link
   * @throws IOException if an IO error occurs while checking the file
   * @since 2.0
   */
  public static boolean isSymlink(final File file) throws IOException {
    if (file == null) {
      throw new NullPointerException("File must not be null");
    }
    return Files.isSymbolicLink(file.toPath());
  }
}

代码示例来源:origin: org.apache.ant/ant

private boolean isDanglingSymlink(final File f) {
    if (!Files.isSymbolicLink(f.toPath())) {
      // it's not a symlink, so clearly it's not a dangling one
      return false;
    }
    // it's a symbolic link, now  check the existence of the (target) file (by "following links")
    final boolean targetFileExists = Files.exists(f.toPath());
    return !targetFileExists;
  }
}

代码示例来源:origin: languagetool-org/languagetool

private LuceneSearcher(File indexDir) throws IOException {
 Path path = indexDir.toPath();
 // symlinks are not supported here, see https://issues.apache.org/jira/browse/LUCENE-6700,
 // so we resolve the link ourselves:
 if (Files.isSymbolicLink(path)) {
  path = indexDir.getCanonicalFile().toPath();
 }
 this.directory = FSDirectory.open(path);
 this.reader = DirectoryReader.open(directory);
 this.searcher = new IndexSearcher(reader);
}
public IndexReader getReader() {

代码示例来源:origin: SonarSource/sonarqube

private static Path createTempFolder(Path workingPath) {
 try {
  Path realPath = workingPath;
  if (Files.isSymbolicLink(realPath)) {
   realPath = realPath.toRealPath();
  }
  Files.createDirectories(realPath);
 } catch (IOException e) {
  throw new IllegalStateException("Failed to create working path: " + workingPath, e);
 }
 try {
  return Files.createTempDirectory(workingPath, TMP_NAME_PREFIX);
 } catch (IOException e) {
  throw new IllegalStateException("Failed to create temporary folder in " + workingPath, e);
 }
}

代码示例来源:origin: org.codehaus.plexus/plexus-utils

public static void chmod( File file, int mode )
  throws IOException
{
  Path path = file.toPath();
  if ( !Files.isSymbolicLink( path ) )
  {
    Files.setPosixFilePermissions( path, getPermissions( mode ) );
  }
}

代码示例来源:origin: apache/ignite

/**
 * @param file File to resolve.
 * @return Resolved file if it is a symbolic link or original file.
 * @throws IOException If failed to resolve symlink.
 */
public static File resolveSymbolicLink(File file) throws IOException {
  Path path = file.toPath();
  return Files.isSymbolicLink(path) ? Files.readSymbolicLink(path).toFile() : file;
}

代码示例来源:origin: apache/ignite

/**
 * @return File status.
 */
private FileStatus fileStatus(File file) throws IOException {
  boolean dir = file.isDirectory();
  java.nio.file.Path path = dir ? null : file.toPath();
  return new FileStatus(dir ? 0 : file.length(), dir, 1, 4 * 1024, file.lastModified(), file.lastModified(),
    /*permission*/null, /*owner*/null, /*group*/null, dir ? null : Files.isSymbolicLink(path) ?
    new Path(Files.readSymbolicLink(path).toUri()) : null, new Path(file.toURI()));
}

代码示例来源:origin: SonarSource/sonarqube

private static void deleteDirectoryImpl(Path path) throws IOException {
 requireNonNull(path, DIRECTORY_CAN_NOT_BE_NULL);
 File file = path.toFile();
 if (!file.exists()) {
  return;
 }
 checkIO(!Files.isSymbolicLink(path), "Directory '%s' is a symbolic link", path);
 checkIO(!file.isFile(), "Directory '%s' is a file", path);
 Files.walkFileTree(path, DeleteRecursivelyFileVisitor.INSTANCE);
 checkIO(!file.exists(), "Unable to delete directory '%s'", path);
}

代码示例来源:origin: google/guava

public void testDeleteRecursively_nonDirectoryFile() throws IOException {
 try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) {
  Path file = fs.getPath("dir/a");
  assertTrue(Files.isRegularFile(file, NOFOLLOW_LINKS));
  MoreFiles.deleteRecursively(file);
  assertFalse(Files.exists(file, NOFOLLOW_LINKS));
  Path symlink = fs.getPath("/symlinktodir");
  assertTrue(Files.isSymbolicLink(symlink));
  Path realSymlinkTarget = symlink.toRealPath();
  assertTrue(Files.isDirectory(realSymlinkTarget, NOFOLLOW_LINKS));
  MoreFiles.deleteRecursively(symlink);
  assertFalse(Files.exists(symlink, NOFOLLOW_LINKS));
  assertTrue(Files.isDirectory(realSymlinkTarget, NOFOLLOW_LINKS));
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testLink() throws Exception {
 String fileName = "some-file.txt";
 long fileSize = 1234;
 createFileWithJunk(fileName, fileSize);
 String linkName = "some-link.txt";
 testLink(linkName, fileName, false, true, v -> {
  assertEquals(fileSize, fileLength(linkName));
  assertFalse(Files.isSymbolicLink(Paths.get(testDir + pathSep + linkName)));
 });
 await();
}

代码示例来源:origin: eclipse-vertx/vert.x

@Test
public void testSymLink() throws Exception {
 // Symlinks require a modified security policy in Windows. -- See http://stackoverflow.com/questions/23217460/how-to-create-soft-symbolic-link-using-java-nio-files
 Assume.assumeFalse(Utils.isWindows());
 String fileName = "some-file.txt";
 long fileSize = 1234;
 createFileWithJunk(fileName, fileSize);
 String symlinkName = "some-sym-link.txt";
 testLink(symlinkName, fileName, true, true, v -> {
  assertEquals(fileSize, fileLength(symlinkName));
  assertTrue(Files.isSymbolicLink(Paths.get(testDir + pathSep + symlinkName)));
  // Now try reading it
  String read = vertx.fileSystem().readSymlinkBlocking(testDir + pathSep + symlinkName);
  assertEquals(fileName, read);
 });
 await();
}

相关文章

微信公众号

最新文章

更多