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

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

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

Path.subpath介绍

暂无

代码示例

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

@Override
public Path subpath(int beginIndex, int endIndex) {
  return delegate.subpath(beginIndex, endIndex);
}

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

/**
 * Truncates path to the last numElements.
 * @param path The path to truncate.
 * @param numElements The number of elements to preserve at the end of the path.
 * @return The truncated path.
 */
public static Path truncatePathToLastElements(Path path, int numElements) {
  if (path.getNameCount() <= numElements) {
    return path;
  }
  return path.subpath(path.getNameCount() - numElements, path.getNameCount());
}

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

@Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attributes)
  {
    if (file.getFileName().toString().endsWith(CLASS_FILE_SUFFIX)) {
      String name = file.subpath(base.getNameCount(), file.getNameCount()).toString();
      list.add(javaName(name.substring(0, name.length() - CLASS_FILE_SUFFIX.length())));
    }
    return FileVisitResult.CONTINUE;
  }
});

代码示例来源:origin: dreamhead/moco

private static Path searchPath(final Path path, final int globIndex) {
  Path root = path.getRoot();
  Path subpath = path.subpath(0, globIndex);
  if (root == null) {
    return subpath;
  }
  return Paths.get(root.toString(), subpath.toString());
}

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

return null;
return path.subpath(fromIndex, toIndex);

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

return null;
return path.subpath(fromIndex, toIndex);

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

private String getPath(final FlowFile flowFile) {
  Path path = Paths.get(flowFile.getAttribute(CoreAttributes.PATH.key()));
  if (path.getNameCount() == 0) {
    return "";
  }
  if (".".equals(path.getName(0).toString())) {
    path = path.getNameCount() == 1 ? null : path.subpath(1, path.getNameCount());
  }
  return path == null ? "" : path.toString() + "/";
}

代码示例来源:origin: Netflix/Priam

private BackupVerificationResult verifyBackup(
      IMetaProxy metaProxy, BackupMetadata latestBackupMetaData) {
    Path metadataLocation = Paths.get(latestBackupMetaData.getSnapshotLocation());
    metadataLocation = metadataLocation.subpath(1, metadataLocation.getNameCount());
    AbstractBackupPath abstractBackupPath = abstractBackupPathProvider.get();
    abstractBackupPath.parseRemote(metadataLocation.toString());
    return metaProxy.isMetaFileValid(abstractBackupPath);
  }
}

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

private void removeIncompleteContent(final String containerName, final Path containerPath, final Path fileToRemove) {
  if (Files.isDirectory(fileToRemove)) {
    final Path lastPathName = fileToRemove.subpath(1, fileToRemove.getNameCount());
    final String fileName = lastPathName.toFile().getName();
    if (fileName.equals(ARCHIVE_DIR_NAME)) {
      return;
    }
    final File[] children = fileToRemove.toFile().listFiles();
    if (children != null) {
      for (final File child : children) {
        removeIncompleteContent(containerName, containerPath, child.toPath());
      }
    }
    return;
  }
  final Path relativePath = containerPath.relativize(fileToRemove);
  final Path sectionPath = relativePath.subpath(0, 1);
  if (relativePath.getNameCount() < 2) {
    return;
  }
  final Path idPath = relativePath.subpath(1, relativePath.getNameCount());
  final String id = idPath.toFile().getName();
  final String sectionName = sectionPath.toFile().getName();
  final ResourceClaim resourceClaim = resourceClaimManager.newResourceClaim(containerName, sectionName, id, false, false);
  if (resourceClaimManager.getClaimantCount(resourceClaim) == 0) {
    removeIncompleteContent(fileToRemove);
  }
}

代码示例来源:origin: jooby-project/jooby

private void onChange(final Kind<?> kind, final Path path) {
 File outputdir = workdir.toFile();
 String filename = Route
   .normalize(Try.apply(() -> path.subpath(1, path.getNameCount()).toString())
     .orElse(path.toString()));
 try {
  if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
   errors.remove(filename);
  } else {
   if (Files.isDirectory(path)) {
    errors.clear();
    compiler.build("dev", outputdir);
   } else {
    compiler.buildOne(filename, outputdir);
    errors.remove(filename);
   }
  }
 } catch (AssetException ex) {
  String localname = ex.getProblems().stream()
    .findFirst()
    .map(AssetProblem::getFilename)
    .orElse(filename);
  errors.put(localname, rewrite(ex));
 } catch (Exception ex) {
  AssetException assetEx = rewrite(new AssetException("compiler",
    new AssetProblem(filename, -1, -1, ex.getMessage(), null), ex));
  errors.put(filename, assetEx);
 }
}

代码示例来源:origin: Netflix/Priam

Path snapshotLocation = Paths.get(backupMetadata.getSnapshotLocation());
result.remotePath =
    snapshotLocation.subpath(1, snapshotLocation.getNameCount()).toString();
return Optional.of(result);

代码示例来源:origin: Netflix/Priam

Assert.assertNotEquals("some_random", backupVerificationResultOptinal.get().remotePath);
Assert.assertEquals(
    location.subpath(1, location.getNameCount()).toString(),
    backupVerificationResultOptinal.get().remotePath);

代码示例来源:origin: stackoverflow.com

Path incomingPath = Paths.get("C:\\cresttest\\parent_3\\child_3_1\\child_3_1_.txt");
//getting C:\cresttest\, adding NEW_PATH to it
Path subPathWithAddition = incomingPath.subpath(0, 2).resolve("NEW_PATH");
//Concatenating C:\cresttest\NEW_PATH\ with \parent_3\child_3_1\child_3_1_.txt
Path finalPath = subPathWithAddition.resolve(incomingPath.subpath(2, incomingPath.getNameCount()));

代码示例来源:origin: spring-cloud/spring-cloud-function

/**
 * @param path entry in the Java runtime filesystem, for example '/modules/java.base/java/lang/Object.class'
 */
public JrtEntryJavaFileObject(Path path) {
  this.pathToClassString = path.subpath(2, path.getNameCount()).toString(); // e.g. java/lang/Object.class
  this.path = path;
}

代码示例来源:origin: spring-cloud/spring-cloud-function

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
  if (file.getNameCount() > 2 && file.toString().endsWith(".class")) {
    // /modules/jdk.rmic/sun/tools/tree/CaseStatement.class
    String moduleName = file.getName(1).toString(); // jdk.rmic
    Path moduleRootPath = file.subpath(0, 2); // /modules/jdk.rmic
    if (!modules.containsKey(moduleName)) {
      modules.put(moduleName, moduleRootPath);
    }
  }
  return FileVisitResult.CONTINUE;
}

代码示例来源:origin: stackoverflow.com

Path path = Paths.get("/temp/some/dir/foo");
int depth = 2;

Path someParent = path.getRoot().resolve(path.subpath(0, path.getNameCount() - depth));

System.out.printf("%-10s: %s%n", "path", path);
System.out.printf("%-10s: %d%n", "depth", depth);
System.out.printf("%-10s: %s%n", "someParent", someParent);

代码示例来源:origin: org.wildfly.swarm/container-api

String archiveNameForClassesDir(Path element) {
  if (element.endsWith("target/classes")) {
    // Maven
    return element.subpath(element.getNameCount() - 3, element.getNameCount() - 2).toString() + ".jar";
  } else if (element.endsWith("build/classes/main") || element.endsWith("build/resources/main")) {
    // Gradle
    return element.subpath(element.getNameCount() - 4, element.getNameCount() - 3).toString() + ".jar";
  } else {
    return UUID.randomUUID().toString() + ".jar";
  }
}

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

public static String archiveNameForClassesDir(Path path) {
  if (path.endsWith(TARGET_CLASSES)) {
    // Maven
    return path.subpath(path.getNameCount() - 3, path.getNameCount() - 2).toString() + JAR;
  } else if (path.endsWith(BUILD_CLASSES_MAIN) || path.endsWith(BUILD_RESOURCES_MAIN)) {
    // Gradle + Gradle 4+
    return path.subpath(path.getNameCount() - 4, path.getNameCount() - 3).toString() + JAR;
  } else {
    return UUID.randomUUID().toString() + JAR;
  }
}

代码示例来源:origin: org.apache.nifi/nifi-standard-processors

private String getPath(final FlowFile flowFile) {
  Path path = Paths.get(flowFile.getAttribute(CoreAttributes.PATH.key()));
  if (path.getNameCount() == 0) {
    return "";
  }
  if (".".equals(path.getName(0).toString())) {
    path = path.getNameCount() == 1 ? null : path.subpath(1, path.getNameCount());
  }
  return path == null ? "" : path.toString() + "/";
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base

@Override
  public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
    if (attrs.isRegularFile()) {
      Path relativePath = file.subpath(startElements, file.getNameCount());
      tasks.add(function.apply(new SourceAndDestination(file.toString(), Os.mergePathsUnix(destination, relativePath.toString()))));
    }
    return FileVisitResult.CONTINUE;
  }
});

相关文章