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

x33g5p2x  于2022-01-25 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(167)

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

Path.isAbsolute介绍

暂无

代码示例

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

@Override
public boolean isAbsolute() {
  return delegate.isAbsolute();
}

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

public static boolean isAbsolutePath(String path) {
  return Paths.get(path).isAbsolute();
}

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

private static void validatePaths(@javax.annotation.Nullable Collection<Path> paths) {
 if (paths != null && paths.stream().anyMatch(p -> !p.isAbsolute())) {
  throw new IllegalStateException("SCM provider returned a changed file with a relative path but paths must be absolute. Please fix the provider.");
 }
}

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

protected static File resolvePath(File baseDir, String path) {
 Path filePath = Paths.get(path);
 if (!filePath.isAbsolute()) {
  filePath = baseDir.toPath().resolve(path);
 }
 return filePath.normalize().toFile();
}

代码示例来源:origin: syncany/syncany

private Path toAbsoluteNormalizedPath(String potentiallyRelativePathStr) {
  Path filePath = Paths.get(potentiallyRelativePathStr);
  
  if (!filePath.isAbsolute()) {
    return Paths.get(root.toString(), filePath.toString()).normalize();
  }
  else {
    return filePath.normalize();
  }
}

代码示例来源:origin: prestodb/presto

public static <T> T parseJson(Path path, Class<T> javaType)
  {
    if (!path.isAbsolute()) {
      path = path.toAbsolutePath();
    }

    checkArgument(exists(path), "File does not exist: %s", path);
    checkArgument(isReadable(path), "File is not readable: %s", path);

    try {
      byte[] json = Files.readAllBytes(path);
      ObjectMapper mapper = new ObjectMapperProvider().get()
          .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
      return mapper.readValue(json, javaType);
    }
    catch (IOException e) {
      throw new IllegalArgumentException(format("Invalid JSON file '%s' for '%s'", path, javaType), e);
    }
  }
}

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

public AutoClosablePath(final Path path) {
  Preconditions.checkNotNull(path, "Path must not be null.");
  Preconditions.checkArgument(path.isAbsolute(), "Path must be absolute.");
  this.path = path;
}

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

public Path metadataFilePath() {
 Optional<String> metadataFilePath = configuration.get(METADATA_FILE_PATH_KEY);
 if (metadataFilePath.isPresent()) {
  Path metadataPath = Paths.get(metadataFilePath.get());
  if (!metadataPath.isAbsolute()) {
   throw MessageException.of(String.format("Property '%s' must point to an absolute path: %s", METADATA_FILE_PATH_KEY, metadataFilePath.get()));
  }
  return project.getBaseDir().resolve(metadataPath);
 } else {
  return project.getWorkDir().resolve(METADATA_DUMP_FILENAME);
 }
}

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

/**
 * Get the file store type of a path. for example, /dev/sdd1(store name) /w2-gst-dev40d(mount
 * point) ext4(type)
 *
 * @return file store type
 */
public String getFileStoreType(final String path) {
 File diskFile = new File(path);
 if (!diskFile.exists()) {
  diskFile = diskFile.getParentFile();
 }
 Path currentPath = diskFile.toPath();
 if (currentPath.isAbsolute() && Files.exists(currentPath)) {
  try {
   FileStore store = Files.getFileStore(currentPath);
   return store.type();
  } catch (IOException e) {
   return null;
  }
 }
 return null;
}

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

if (f.getName().compareTo(filename.toString()) == 0) {
 File changedFile;
 if (filename.isAbsolute()) {
  changedFile = new File(filename.toString());
 } else {

代码示例来源:origin: googleapis/google-cloud-java

@Override
public Iterator<Path> iterator() {
 return new LazyPathIterator(
   cloudPath.getFileSystem(), prefix, blobIterator, filter, dir.isAbsolute());
}

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

public void assertIsRelative(final AssertionInfo info, final Path actual) {
 assertNotNull(info, actual);
 if (actual.isAbsolute()) throw failures.failure(info, shouldBeRelativePath(actual));
}

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

public void assertIsAbsolute(final AssertionInfo info, final Path actual) {
 assertNotNull(info, actual);
 if (!actual.isAbsolute()) throw failures.failure(info, shouldBeAbsolutePath(actual));
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Creates a new instance of {@link AlluxioFuseFileSystem}.
 *
 * @param fs Alluxio file system
 * @param opts options
 * @param conf Alluxio configuration
 */
public AlluxioFuseFileSystem(FileSystem fs, AlluxioFuseOptions opts, AlluxioConfiguration conf) {
 super();
 mFsName = conf.get(PropertyKey.FUSE_FS_NAME);
 mFileSystem = fs;
 mAlluxioRootPath = Paths.get(opts.getAlluxioRoot());
 mNextOpenFileId = 0L;
 mOpenFiles = new IndexedSet<>(ID_INDEX, PATH_INDEX);
 final int maxCachedPaths = conf.getInt(PropertyKey.FUSE_CACHED_PATHS_MAX);
 mIsUserGroupTranslation
   = conf.getBoolean(PropertyKey.FUSE_USER_GROUP_TRANSLATION_ENABLED);
 mPathResolverCache = CacheBuilder.newBuilder()
   .maximumSize(maxCachedPaths)
   .build(new PathCacheLoader());
 Preconditions.checkArgument(mAlluxioRootPath.isAbsolute(),
   "alluxio root path should be absolute");
}

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

public TempFolder provide(ScannerProperties scannerProps) {
 if (tempFolder == null) {
  String workingPathName = StringUtils.defaultIfBlank(scannerProps.property(CoreProperties.GLOBAL_WORKING_DIRECTORY), CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE);
  Path workingPath = Paths.get(workingPathName);
  if (!workingPath.isAbsolute()) {
   Path home = findSonarHome(scannerProps);
   workingPath = home.resolve(workingPath).normalize();
  }
  try {
   cleanTempFolders(workingPath);
  } catch (IOException e) {
   LOG.error(String.format("failed to clean global working directory: %s", workingPath), e);
  }
  Path tempDir = createTempFolder(workingPath);
  tempFolder = new DefaultTempFolder(tempDir.toFile(), true);
 }
 return tempFolder;
}

代码示例来源:origin: joel-costigliola/assertj-core

public void assertIsRelative(final AssertionInfo info, final Path actual) {
 assertNotNull(info, actual);
 if (actual.isAbsolute()) throw failures.failure(info, shouldBeRelativePath(actual));
}

代码示例来源:origin: joel-costigliola/assertj-core

public void assertIsAbsolute(final AssertionInfo info, final Path actual) {
 assertNotNull(info, actual);
 if (!actual.isAbsolute()) throw failures.failure(info, shouldBeAbsolutePath(actual));
}

代码示例来源:origin: line/armeria

@Override
  protected WebResourceSet createMainResourceSet() {
    final Path docBase = config.docBase();
    assert docBase.isAbsolute();

    final String docBaseStr = docBase.toString();
    getContext().setDocBase(docBaseStr);

    if (Files.isDirectory(docBase)) {
      return new DirResourceSet(this, "/", docBaseStr, "/");
    }

    final Optional<String> jarRootOpt = config.jarRoot();
    if (jarRootOpt.isPresent()) { // If docBase is a JAR file
      final String jarRoot = jarRootOpt.get();
      if ("/".equals(jarRoot)) {
        return new JarResourceSet(this, "/", docBaseStr, "/");
      } else {
        return new JarSubsetResourceSet(this, "/", docBaseStr, "/", jarRoot);
      }
    }

    throw new IllegalArgumentException(sm.getString("standardRoot.startInvalidMain", docBaseStr));
  }
}

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

/**
 * Checks that the given file can be deleted, throwing an exception if it can't.
 */
private void checkDeletable(File file, DeleteMode mode, Path path) throws IOException {
 if (file.isRootDirectory()) {
  throw new FileSystemException(path.toString(), null, "can't delete root directory");
 }
 if (file.isDirectory()) {
  if (mode == DeleteMode.NON_DIRECTORY_ONLY) {
   throw new FileSystemException(path.toString(), null, "can't delete: is a directory");
  }
  checkEmpty(((Directory) file), path);
 } else if (mode == DeleteMode.DIRECTORY_ONLY) {
  throw new FileSystemException(path.toString(), null, "can't delete: is not a directory");
 }
 if (file == workingDirectory && !path.isAbsolute()) {
  // this is weird, but on Unix at least, the file system seems to be happy to delete the
  // working directory if you give the absolute path to it but fail if you use a relative path
  // that resolves to the working directory (e.g. "" or ".")
  throw new FileSystemException(path.toString(), null, "invalid argument");
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testRelativityOfResolve() throws IOException {
 try (FileSystem fs = getTestBucket()) {
  Path abs1 = fs.getPath("/dir");
  Path abs2 = abs1.resolve("subdir/");
  Path rel1 = fs.getPath("dir");
  Path rel2 = rel1.resolve("subdir/");
  // children of absolute paths are absolute,
  // children of relative paths are relative.
  assertThat(abs1.isAbsolute()).isTrue();
  assertThat(abs2.isAbsolute()).isTrue();
  assertThat(rel1.isAbsolute()).isFalse();
  assertThat(rel2.isAbsolute()).isFalse();
 }
}

相关文章