Java 8 Path - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Path class.

This code example shows how to use the following methods:getFileName, getNameCount, subpath, toString
    protected AssetUri getUri(Path relativePath) {
        return getUri(sourceId, relativePath);
    } 
 
    protected AssetUri getUri(Name moduleId, Path relativePath) {
        if (relativePath.getNameCount() > 1) {
            Path assetPath = relativePath.subpath(0, 1);
            Path filename = relativePath.getFileName();
            String extension = Files.getFileExtension(filename.toString());
            String nameOnly = filename.toString().substring(0, filename.toString().length() - extension.length() - 1);
            AssetType assetType = AssetType.getTypeFor(assetPath.toString(), extension);
            if (assetType != null) {
                return assetType.getUri(moduleId, nameOnly);
            } 
        } 
        return null; 
    } 
 
    protected AssetUri getUri(String relativePath) {
        return getUri(sourceId, relativePath);
7
CodeRank
This code example shows how to use the following methods:getParent, resolve
      BuildContext context,
      BuildableContext buildableContext) {
 
    ImmutableList.Builder<Step> steps = ImmutableList.builder(); 
 
    Path workingDirectory = outputFile.getParent();
    steps.add(new MakeCleanDirectoryStep(workingDirectory));
 
    // A CopyResourcesStep is needed so that a file that is at java/com/example/resource.txt in the 
    // repository will be added as com/example/resource.txt in the resulting JAR (assuming that 
    // "/java/" is listed under src_roots in .buckconfig). 
    Path tempJarFolder = workingDirectory.resolve("tmp");
    steps.add(new CopyResourcesStep( 
        getResolver(), 
        getBuildTarget(), 
        filesForGwtModule,
        tempJarFolder,
        context.getJavaPackageFinder()));
 
    steps.add(new JarDirectoryStep( 

7
CodeRank
This code example shows how to use the following methods:resolve
  // package-private to the com.facebook.buck.rules directory. Currently, they are also used in the 
  // com.facebook.buck.shell package, but these values should be injected into shell commands rather 
  // than hardcoded therein. This ensures that shell commands stay build-rule-agnostic. 
 
  public static final String GEN_DIR = BUCK_OUTPUT_DIRECTORY + "/gen";
  public static final Path GEN_PATH = BUCK_OUTPUT_PATH.resolve("gen");
 
  public static final String BIN_DIR = BUCK_OUTPUT_DIRECTORY + "/bin";
  public static final Path BIN_PATH = BUCK_OUTPUT_PATH.resolve("bin");
 
  public static final String ANNOTATION_DIR = BUCK_OUTPUT_DIRECTORY + "/annotation";
  public static final Path ANNOTATION_PATH = BUCK_OUTPUT_PATH.resolve("annotation");
 
  public static final Path LOG_PATH = BUCK_OUTPUT_PATH.resolve("log");
 
  public static final Path BUCK_TRACE_DIR = BUCK_OUTPUT_PATH.resolve("log/traces");
 
  /** 
   * This variable is package-private because conceptually, only parsing logic should be concerned 
   * with the files that define build rules. Note that if the value of this variable changes, the 
   * {@code BUILD_RULES_FILE_NAME} constant in {@code buck.py} must be updated, as well. 
7
CodeRank
This code example shows how to use the following methods:resolve
    // no exception 
  } 
   
  public void testDeleteTwoFilesIgnoringExceptions() throws Exception {
    Path dir = createTempDir();
    Path file1 = dir.resolve("file1");
    Path file2 = dir.resolve("file2");
    // only create file2 
    Files.createFile(file2);
    IOUtils.deleteFilesIgnoringExceptions(file1, file2);
    assertFalse(Files.exists(file2));
    // no exception 
    // actually deletes file2 
  } 
   
  public void testDeleteFileIfExists() throws Exception {
    Path dir = createTempDir();
    Path file1 = dir.resolve("file1");
    Files.createFile(file1);
    IOUtils.deleteFilesIfExist(file1);
7
CodeRank
This code example shows how to use the following methods:getFileName, resolve
    assertReadText(autoOutFile("TXT")); 
    assertReadText(autoOutFile("TEXT")); 
  } 
   
  private Path rawTextFile(String ext) throws Exception {
    Path f = testDir.resolve("testfile." +  ext);
    BufferedWriter w = Files.newBufferedWriter(f, StandardCharsets.UTF_8);
    w.write(TEXT);
    w.newLine();
    w.close();
    return f;
  } 
   
  private Path rawGzipFile(String ext) throws Exception {
    Path f = testDir.resolve("testfile." +  ext);
    OutputStream os = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP, Files.newOutputStream(f));
    writeText(os);
    return f;
  } 
 

7
CodeRank
This code example shows how to use the following methods:resolve
            "Google Inc.:Google APIs:17", 
            androidDirectoryResolver,
            /* aaptOverride */ Optional.<Path>absent());
    assertTrue(androidPlatformTargetOption1.isPresent());
    assertEquals( 
        ImmutableList.of( 
            pathToAndroidSdkDir.resolve("platforms/android-17/android.jar"),
            pathToAndroidSdkDir.resolve("add-ons/addon-google_apis-google-17/libs/effects.jar"),
            pathToAndroidSdkDir.resolve("add-ons/addon-google_apis-google-17/libs/maps.jar"),
            pathToAndroidSdkDir.resolve("add-ons/addon-google_apis-google-17/libs/usb.jar")),
        androidPlatformTargetOption1.get().getBootclasspathEntries());
 
    // This one should only include android.jar 
    Optional<AndroidPlatformTarget> androidPlatformTargetOption2 =
        AndroidPlatformTarget.getTargetForId( 
            "android-17", 
            androidDirectoryResolver,
            /* aaptOverride */ Optional.<Path>absent());
    assertTrue(androidPlatformTargetOption2.isPresent());
    assertEquals( 

7
CodeRank
This code example shows how to use the following methods:getParent
  public ImmutableList<Step> getBuildSteps( 
      BuildContext context,
      BuildableContext buildableContext) {
 
    // Cache the output source and header. 
    buildableContext.recordArtifact(YaccStep.getHeaderOutputPath(outputPrefix));
    buildableContext.recordArtifact(YaccStep.getSourceOutputPath(outputPrefix));
 
    return ImmutableList.of( 
        new MkdirStep(outputPrefix.getParent()),
        new RmStep(getHeaderOutputPath(outputPrefix), /* shouldForceDeletion */ true),
        new RmStep(getSourceOutputPath(outputPrefix), /* shouldForceDeletion */ true),
        new YaccStep( 
            getResolver().getPath(yacc),
            flags,
            outputPrefix,
            getResolver().getPath(input)));
  } 
 
  @Nullable 
7
CodeRank
This code example shows how to use the following methods:getParent
    ImmutableList.Builder<Step> commands = ImmutableList.builder(); 
 
    // Clear out the old file, if it exists. 
    commands.add(new RmStep(pathToOutputFile,
        /* shouldForceDeletion */ true, 
        /* shouldRecurse */ false)); 
 
    // Make sure the directory for the output file exists. 
    commands.add(new MkdirStep(pathToOutputFile.getParent()));
 
    commands.add(new GenerateManifestStep( 
        getResolver().getPath(skeletonFile),
        ImmutableSet.copyOf(getResolver().getAllPaths(manifestFiles)),
        getPathToOutputFile())); 
 
    buildableContext.recordArtifact(pathToOutputFile);
    return commands.build(); 
  } 
 
  @Override 
  public Path getPathToOutputFile() {
7
CodeRank
This code example shows how to use the following methods:getFileName, toString
7
CodeRank
This code example shows how to use the following methods:isAbsolute, relativize, resolve, startsWith, toAbsolutePath
        result = 31 * result + kind.hashCode();
        return result;
    } 
 
    private static Path normalizePath(Path dir, Path path) {
        if (path.startsWith(dir)) {
            return dir.relativize(path);
        } 
        if (path.isAbsolute() && path.startsWith(dir.toAbsolutePath())) {
            return dir.toAbsolutePath().relativize(path);
        } 
        return path;
    } 
} 
7
CodeRank
See Code Examples for Java 8 Path Methods: