本文整理汇总了Java中java.nio.file.Path.getRoot方法的典型用法代码示例。如果您正苦于以下问题:Java Path.getRoot方法的具体用法?Java Path.getRoot怎么用?Java Path.getRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.Path
的用法示例。
在下文中一共展示了Path.getRoot方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getN4JSProject
import java.nio.file.Path; //导入方法依赖的package包/类
public N4JSProject getN4JSProject(URI location) {
checkArgument(location.isFile(), "Expecting file URI. Was: " + location);
boolean external = false;
if (null != installLocationProvider.getTargetPlatformInstallLocation()) {
Path projectPath = new File(location.toFileString()).toPath();
Path nodeModulesPath = new File(installLocationProvider.getTargetPlatformNodeModulesLocation()).toPath();
try {
final Path projectRoot = projectPath.getRoot();
final Path nodeModulesRoot = nodeModulesPath.getRoot();
if (Objects.equal(projectRoot, nodeModulesRoot)) {
final String relativePath = nodeModulesPath.relativize(projectPath).toString();
external = location.lastSegment().equals(relativePath);
}
} catch (final IllegalArgumentException e) {
final String message = "Error while trying to relativize paths. Project path was: " + projectPath
+ " target platform node modules location was: " + nodeModulesPath + ".";
LOGGER.error(message, e);
throw new RuntimeException(message, e);
}
}
return new N4JSProject(location, external, this);
}
示例2: show
import java.nio.file.Path; //导入方法依赖的package包/类
@Override
@FXThread
public void show(@NotNull final Window owner) {
super.show(owner);
Path initDirectory = getInitDirectory();
if (initDirectory == null) {
initDirectory = Paths.get(System.getProperty("user.home"));
}
final Path toExpand = initDirectory;
final Path root = initDirectory.getRoot();
final ResourceTree resourceTree = getResourceTree();
resourceTree.fill(root);
resourceTree.setOnLoadHandler(finished -> {
if (finished) {
resourceTree.expandTo(toExpand, true);
}
});
EXECUTOR_MANAGER.addFXTask(resourceTree::requestFocus);
}
示例3: stripRoot
import java.nio.file.Path; //导入方法依赖的package包/类
static String stripRoot(Path path) {
if (path.getRoot() != null) {
String root = path.getRoot().toString();
String filename = path.toString().substring(root.length());
String separator = path.getFileSystem().getSeparator();
while (filename.startsWith(separator)) {
filename = filename.substring(separator.length());
}
return filename;
}
return path.toString();
}
示例4: toSafeFilePath
import java.nio.file.Path; //导入方法依赖的package包/类
/**
* Map a resource name to a "safe" file path. Returns {@code null} if
* the resource name cannot be converted into a "safe" file path.
*
* Resource names with empty elements, or elements that are "." or ".."
* are rejected, as are resource names that translates to a file path
* with a root component.
*/
private static Path toSafeFilePath(FileSystem fs, String name) {
// scan elements of resource name
int next;
int off = 0;
while ((next = name.indexOf('/', off)) != -1) {
int len = next - off;
if (!mayTranslate(name, off, len)) {
return null;
}
off = next + 1;
}
int rem = name.length() - off;
if (!mayTranslate(name, off, rem)) {
return null;
}
// convert to file path
Path path;
if (File.separatorChar == '/') {
path = fs.getPath(name);
} else {
// not allowed to embed file separators
if (name.contains(File.separator))
return null;
path = fs.getPath(name.replace('/', File.separatorChar));
}
// file path not allowed to have root component
return (path.getRoot() == null) ? path : null;
}