java.nio.file.Path#toAbsolutePath ( )源码实例Demo

下面列出了java.nio.file.Path#toAbsolutePath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: testgrid   文件: InfrastructurePlanGenerator.java
private void validate(Path templatePath, Map<String, String> inputParams, Path output) {
    if (!Files.exists(templatePath)) {
        throw new IllegalArgumentException("Provided template path '" + templatePath +
                "' does not exist.");
    }

    output = output.toAbsolutePath();
    Path outputParent = output.getParent();
    if (outputParent != null && !Files.exists(outputParent)) {
        throw new IllegalArgumentException("Output cannot be created, its parent folder does not exist'" +
                output.getParent());
    } else if (Files.exists(output)) {
        logger.warn("Output path exists already. It will be overwritten: " + output);
    }

}
 
源代码2 项目: openjdk-jdk8u   文件: JDKToolFinder.java
private static String getTool(String tool, String property) throws FileNotFoundException {
    String jdkPath = System.getProperty(property);

    if (jdkPath == null) {
        throw new RuntimeException(
                "System property '" + property + "' not set. This property is normally set by jtreg. "
                + "When running test separately, set this property using '-D" + property + "=/path/to/jdk'.");
    }

    Path toolName = Paths.get("bin", tool + (Platform.isWindows() ? ".exe" : ""));

    Path jdkTool = Paths.get(jdkPath, toolName.toString());
    if (!jdkTool.toFile().exists()) {
        throw new FileNotFoundException("Could not find file " + jdkTool.toAbsolutePath());
    }

    return jdkTool.toAbsolutePath().toString();
}
 
源代码3 项目: hottub   文件: PathFileObject.java
/**
 * Create a PathFileObject whose binary name might be inferred from its
 * position on a search path.
 */
static PathFileObject createSimplePathFileObject(JavacPathFileManager fileManager,
        final Path path) {
    return new PathFileObject(fileManager, path) {
        @Override
        String inferBinaryName(Iterable<? extends Path> paths) {
            Path absPath = path.toAbsolutePath();
            for (Path p: paths) {
                Path ap = p.toAbsolutePath();
                if (absPath.startsWith(ap)) {
                    try {
                        Path rp = ap.relativize(absPath);
                        if (rp != null) // maybe null if absPath same as ap
                            return toBinaryName(rp);
                    } catch (IllegalArgumentException e) {
                        // ignore this p if cannot relativize path to p
                    }
                }
            }
            return null;
        }
    };
}
 
源代码4 项目: benchmarks   文件: ResultsAggregator.java
public ResultsAggregator(final Path directory, final double reportOutputScalingRatio)
{
    if (!exists(directory))
    {
        throw new IllegalArgumentException("directory does not exist: " + directory.toAbsolutePath());
    }

    if (!isDirectory(directory))
    {
        throw new IllegalArgumentException(directory.toAbsolutePath() + " is not a directory!");
    }

    if (isNaN(reportOutputScalingRatio) || compare(reportOutputScalingRatio, 0.0) <= 0)
    {
        throw new IllegalArgumentException(
            "report output value scale ratio must a positive number, got: " + reportOutputScalingRatio);
    }

    this.directory = directory;
    this.reportOutputScalingRatio = reportOutputScalingRatio;
}
 
源代码5 项目: fabric-loader   文件: ModContainer.java
void setupRootPath() {
	if (root != null) {
		throw new RuntimeException("Not allowed to setup mod root path twice!");
	}

	try {
		Path holder = UrlUtil.asPath(originUrl).toAbsolutePath();
		if (Files.isDirectory(holder)) {
			root = holder.toAbsolutePath();
		} else /* JAR */ {
			FileSystemUtil.FileSystemDelegate delegate = FileSystemUtil.getJarFileSystem(holder, false);
			if (delegate.get() == null) {
				throw new RuntimeException("Could not open JAR file " + holder.getFileName() + " for NIO reading!");
			}

			root = delegate.get().getRootDirectories().iterator().next();

			// We never close here. It's fine. getJarFileSystem() will handle it gracefully, and so should mods
		}
	} catch (IOException | UrlConversionException e) {
		throw new RuntimeException("Failed to find root directory for mod '" + info.getId() + "'!", e);
	}
}
 
源代码6 项目: jdk8u-dev-jdk   文件: JDKToolFinder.java
private static String getTool(String tool, String property) throws FileNotFoundException {
    String jdkPath = System.getProperty(property);

    if (jdkPath == null) {
        throw new RuntimeException(
                "System property '" + property + "' not set. This property is normally set by jtreg. "
                + "When running test separately, set this property using '-D" + property + "=/path/to/jdk'.");
    }

    Path toolName = Paths.get("bin", tool + (Platform.isWindows() ? ".exe" : ""));

    Path jdkTool = Paths.get(jdkPath, toolName.toString());
    if (!jdkTool.toFile().exists()) {
        throw new FileNotFoundException("Could not find file " + jdkTool.toAbsolutePath());
    }

    return jdkTool.toAbsolutePath().toString();
}
 
源代码7 项目: TencentKona-8   文件: JDKToolFinder.java
private static String getTool(String tool, String property) throws FileNotFoundException {
    String jdkPath = System.getProperty(property);

    if (jdkPath == null) {
        throw new RuntimeException(
                "System property '" + property + "' not set. This property is normally set by jtreg. "
                + "When running test separately, set this property using '-D" + property + "=/path/to/jdk'.");
    }

    Path toolName = Paths.get("bin", tool + (Platform.isWindows() ? ".exe" : ""));

    Path jdkTool = Paths.get(jdkPath, toolName.toString());
    if (!jdkTool.toFile().exists()) {
        throw new FileNotFoundException("Could not find file " + jdkTool.toAbsolutePath());
    }

    return jdkTool.toAbsolutePath().toString();
}
 
源代码8 项目: mycore   文件: MCRTransferPackageCommands.java
@MCRCommand(help = "Imports a transfer package located at {0}. Where {0} is the absolute path to the tar file. "
    + "The parameter {1} is optional and can be omitted. You can specify a mycore id where the first object of "
    + "import.xml should be attached.",
    syntax = "import transfer package from tar {0} to {1}")
public static List<String> importTransferPackageFromTar(String pathToTar, String mycoreTargetId) throws Exception {
    Path tar = Paths.get(pathToTar);
    if (!Files.exists(tar)) {
        throw new FileNotFoundException(tar.toAbsolutePath() + " does not exist.");
    }
    Path targetDirectory = MCRTransferPackageUtil.getTargetDirectory(tar);

    List<String> commands = new ArrayList<>();
    commands.add("_import transfer package untar " + pathToTar);
    commands.add("_import transfer package from directory " + targetDirectory + " to " + mycoreTargetId);
    commands.add("_import transfer package clean up " + targetDirectory);
    return commands;
}
 
源代码9 项目: bazel   文件: BlackBoxTestContext.java
/**
 * Take the value from environment variable and assert that it is a path, and the file or
 * directory, specified by this path, exists.
 *
 * @param name name of the environment variable
 * @return Path to the file where the value of environment variable points
 */
private static Path getPathFromEnv(String name) {
  String pathStr = System.getenv(name);
  assertThat(pathStr).isNotNull();
  Path path = Paths.get(pathStr);
  assertThat(Files.exists(path)).isTrue();
  return path.toAbsolutePath();
}
 
源代码10 项目: Advanced_Java   文件: PathDemos.java
public static void main(String[] args) {
    // Using Paths.get(...) to create a Path
    Path dictionary = Paths.get("/", "usr", "share", "dict", "web2");
    System.out.println(dictionary);

    Path home = Paths.get("/Users/kousen");
    System.out.println(home);

    // Using resolve to find nested paths
    Path docs = home.resolve("Documents");
    System.out.println(docs);

    // Can resolve siblings as well
    Path downloads = docs.resolveSibling("Downloads");
    System.out.println(downloads);

    // Project directory
    Path project = Paths.get(".");
    System.out.println(project);
    System.out.println(project.toAbsolutePath());
    System.out.println("As a URI: " + project.toUri());

    // Normalize a path
    Path p = Paths.get("/Users/kousen/Documents/./IntelliJ/..").normalize();
    System.out.println("Normalized: " + p);

    System.out.println("parent: " + project.toAbsolutePath().getParent());
    System.out.println("file name: " + project.toAbsolutePath().getFileName());
    System.out.println("root: " + project.toAbsolutePath().getRoot());
    for (Path path : project.toAbsolutePath()) {
        System.out.println(path);
    }

    File localDir = new File("..");
    System.out.println(localDir);
    System.out.println(localDir.toPath().toAbsolutePath().normalize());
}
 
源代码11 项目: clarity   文件: LiveSource.java
public LiveSource(Path filePath, long timeout, TimeUnit timeUnit) {
    this.timeout = timeout;
    this.timeUnit = timeUnit;

    this.filePath = filePath.toAbsolutePath();
    resetLastTick();
    handleFileChange();

    final Thread watcherThread = new Thread(this::watcherThread);
    watcherThread.setName("clarity-livesource-watcher");
    watcherThread.setDaemon(true);
    watcherThread.start();
}
 
源代码12 项目: js-dossier   文件: DossierFileSystem.java
/**
 * Returns the path of the given source file relative to the common input source directory.
 *
 * @throws IllegalArgumentException if the given file is not under the common source directory.
 */
public Path getSourceRelativePath(Path sourceFile) {
  if (sourcePrefix.isAbsolute()) {
    sourceFile = sourceFile.toAbsolutePath();
  }
  checkArgument(
      sourceFile.startsWith(sourcePrefix),
      "The requested path is not a recognized source file: %s",
      sourceFile);
  return sourcePrefix.relativize(sourceFile.normalize());
}
 
源代码13 项目: module-ballerina-kubernetes   文件: KnativeUtils.java
/**
 * Deletes a given directory.
 *
 * @param path path to directory
 * @throws KubernetesPluginException if an error occurs while deleting
 */
public static void deleteDirectory(Path path) throws KubernetesPluginException {
    Path pathToBeDeleted = path.toAbsolutePath();
    if (!Files.exists(pathToBeDeleted)) {
        return;
    }
    try {
        Files.walk(pathToBeDeleted)
                .sorted(Comparator.reverseOrder())
                .map(Path::toFile)
                .forEach(File::delete);
    } catch (IOException e) {
        throw new KubernetesPluginException("unable to delete directory: " + path, e);
    }
}
 
源代码14 项目: daq   文件: Pubber.java
private byte[] getFileBytes(String dataFile) {
  Path dataPath = Paths.get(dataFile);
  try {
    return Files.readAllBytes(dataPath);
  } catch (Exception e) {
    throw new RuntimeException("While getting data from " + dataPath.toAbsolutePath(), e);
  }
}
 
源代码15 项目: orion   文件: FileKeyStore.java
private List<String> readPasswords(final Path passwords) throws IOException {
  try {
    return Files.readAllLines(passwords);
  } catch (final IOException ex) {
    throw new IOException("Failed to read password list '" + passwords.toAbsolutePath() + "'", ex);
  }
}
 
源代码16 项目: recheck   文件: GoldenMasterProviderImpl.java
private Path getStates( final Path projectRoot, final String filePath ) {
	if ( projectRoot != null && filePath != null ) {
		logger.debug( "Looking for Golden Master files in '{}'.", projectRoot );
		final Path statePath = Paths.get( projectRoot.toAbsolutePath().toString(), filePath );
		if ( statePath.toFile().exists() ) {
			return statePath.toAbsolutePath();
		}
	}
	return null;
}
 
源代码17 项目: buck   文件: IjSourceRootSimplifier.java
public BottomUpPathMerger(
    Iterable<IjFolder> foldersToWalk,
    int limit,
    Path moduleLocation,
    PackagePathCache packagePathCache,
    ImmutableSet<Path> traversalBoundaryPaths) {
  this.tree = new MutableDirectedGraph<>();
  this.packagePathCache = packagePathCache;
  this.mergePathsMap = new HashMap<>();
  this.moduleLocation = moduleLocation.toAbsolutePath();

  for (IjFolder folder : foldersToWalk) {
    Path path = folder.getPath();
    mergePathsMap.put(path, folder);
    while (getPathNameCount(path) > limit) {
      Path parent = this.moduleLocation.resolve(path).getParent();
      if (parent == null) {
        break;
      }
      parent = this.moduleLocation.relativize(parent);

      boolean isParentAndGrandParentAlreadyInTree = tree.containsNode(parent);
      tree.addEdge(parent, path);
      if (isParentAndGrandParentAlreadyInTree) {
        break;
      }

      path = parent;
    }
  }

  topLevels = findTopLevels(foldersToWalk, traversalBoundaryPaths);
}
 
源代码18 项目: libreveris   文件: UnixDescriptor.java
@Override
public String getDeleteCommand (Path file)
{
    return "rm -v -f \"" + file.toAbsolutePath() + "\"";
}
 
源代码19 项目: galleon   文件: Errors.java
static String deleteFile(Path p) {
    return "Failed to delete " + p.toAbsolutePath();
}
 
源代码20 项目: desktopclient-java   文件: Kontalk.java
Kontalk(Path appDir) {
    mAppDir = appDir.toAbsolutePath();
}