本文整理了Java中java.nio.file.Path.getRoot()
方法的一些代码示例,展示了Path.getRoot()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Path.getRoot()
方法的具体详情如下:
包路径:java.nio.file.Path
类名称:Path
方法名:getRoot
暂无
代码示例来源:origin: apache/groovy
@Override
public Path getRoot() {
return delegate.getRoot();
}
代码示例来源:origin: GoogleContainerTools/jib
/**
* Resolves this path against another relative path (by the name elements of {@code
* relativePath}).
*
* @param relativePath the relative path to resolve against
* @return a new {@link AbsoluteUnixPath} representing the resolved path
*/
public AbsoluteUnixPath resolve(Path relativePath) {
Preconditions.checkArgument(
relativePath.getRoot() == null, "Cannot resolve against absolute Path: " + relativePath);
return AbsoluteUnixPath.fromPath(Paths.get(unixPath).resolve(relativePath));
}
代码示例来源:origin: apache/nifi
protected static String calculateDefaultOutputDirectory(Path currentPath) {
Path currentAbsolutePath = currentPath.toAbsolutePath();
Path parent = currentAbsolutePath.getParent();
if (currentAbsolutePath.getRoot().equals(parent)) {
return parent.toString();
} else {
Path currentNormalizedPath = currentAbsolutePath.normalize();
return "../" + currentNormalizedPath.getFileName().toString();
}
}
代码示例来源: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: GoogleContainerTools/jib
/**
* Gets a new {@link AbsoluteUnixPath} from a {@link Path}. The {@code path} must be absolute
* (indicated by a non-null {@link Path#getRoot}).
*
* @param path the absolute {@link Path} to convert to an {@link AbsoluteUnixPath}.
* @return a new {@link AbsoluteUnixPath}
*/
public static AbsoluteUnixPath fromPath(Path path) {
Preconditions.checkArgument(
path.getRoot() != null, "Cannot create AbsoluteUnixPath from non-absolute Path: " + path);
ImmutableList.Builder<String> pathComponents =
ImmutableList.builderWithExpectedSize(path.getNameCount());
for (Path pathComponent : path) {
pathComponents.add(pathComponent.toString());
}
return new AbsoluteUnixPath(pathComponents.build());
}
代码示例来源:origin: MovingBlocks/Terasology
/**
* Searches for a parent directory containing the natives directory
*
* @param startPath path to start from
* @param maxDepth max directory levels to search
* @return the adjusted path containing the natives directory or null if not found
*/
private Path findNativesHome(Path startPath, int maxDepth) {
int levelsToSearch = maxDepth;
Path checkedPath = startPath;
while (levelsToSearch > 0) {
File dirToTest = new File(checkedPath.toFile(), NATIVES_DIR);
if (dirToTest.exists()) {
System.out.println("Found the natives dir: " + dirToTest);
return checkedPath;
}
checkedPath = checkedPath.getParent();
if (checkedPath.equals(startPath.getRoot())) {
System.out.println("Uh oh, reached the root path, giving up");
return null;
}
levelsToSearch--;
}
System.out.println("Failed to find the natives dir within " + maxDepth + " levels of " + startPath);
return null;
}
代码示例来源:origin: GoogleContainerTools/jib
/**
* Adds a {@link TarArchiveEntry} if its extraction path does not exist yet. Also adds all of
* the parent directories on the extraction path.
*
* @param tarArchiveEntry the {@link TarArchiveEntry}
*/
private void add(TarArchiveEntry tarArchiveEntry) {
if (names.contains(tarArchiveEntry.getName())) {
return;
}
// Adds all directories along extraction paths to explicitly set permissions for those
// directories.
Path namePath = Paths.get(tarArchiveEntry.getName());
if (namePath.getParent() != namePath.getRoot()) {
add(new TarArchiveEntry(DIRECTORY_FILE, namePath.getParent().toString()));
}
entries.add(tarArchiveEntry);
names.add(tarArchiveEntry.getName());
}
代码示例来源:origin: spotbugs/spotbugs
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
void npe6() throws IOException{
use(PATH.getRoot().getNameCount());
}
代码示例来源:origin: neo4j/neo4j
rootPath.resolve( urlPath.getRoot().relativize( urlPath ) ).normalize().toAbsolutePath();
代码示例来源:origin: org.apache.lucene/lucene-core
devName = path.getRoot().resolve(devName).toRealPath().getFileName().toString();
Path sysinfo = path.getRoot().resolve("sys").resolve("block");
Path devsysinfo = null;
int matchlen = 0;
代码示例来源:origin: embulk/embulk
Path built;
if (dirNormalized.isAbsolute()) {
built = dirNormalized.getRoot();
} else {
built = Paths.get("");
代码示例来源:origin: syncany/syncany
assertNotNull("Files are not equal: Expected file is " + expectedFile + ", actual file is null.", actualFile);
Path root = Paths.get(actualFile.getAbsolutePath()).getRoot();
FileVersionComparator fileVersionComparator = new FileVersionComparator(root.toFile(), "SHA1");
代码示例来源:origin: org.eclipse.jetty/jetty-util
Path root = path.getRoot();
if (root != null)
代码示例来源:origin: de.pfabulist.lindwurm/memoryntfs
private Path getGuestPath(Path guest, Path hostKid) {
Path ret = guest.getRoot();
for ( Path el : hostKid ) {
ret = ret.resolve(el.toString());
}
return ret;
}
代码示例来源:origin: apache/incubator-openwhisk-devtools
private File findSourceRoot(String packageName, Path sourcePath) throws IOException {
int packageSections = Math.toIntExact(packageName.codePoints().filter(ch -> ch =='.').count()) + 1 ;
packageSections++;//increment to include actual filename
return sourcePath.getRoot().resolve(sourcePath.subpath(0, sourcePath.getNameCount()-packageSections)).toFile();
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { Windows.class, RootComponent.class } )
public void testWindowsNoRootComponentGetRootHasNoRootComponent() {
assertThat( FS.getPath( "\\foo" ).getRoot() ).isEqualTo( FS.getPath( "\\" ) );
}
代码示例来源:origin: BruceEckel/OnJava8-Examples
static void info(Path p) {
show("toString", p);
show("Exists", Files.exists(p));
show("RegularFile", Files.isRegularFile(p));
show("Directory", Files.isDirectory(p));
show("Absolute", p.isAbsolute());
show("FileName", p.getFileName());
show("Parent", p.getParent());
show("Root", p.getRoot());
System.out.println("******************");
}
public static void main(String[] args) {
代码示例来源:origin: shrinkwrap/shrinkwrap
@Test
public void getPathRootFromEmptyString() {
final Path path = fileSystem.getPath("");
Assert.assertNull("Root path of empty string should be null", path.getRoot());
}
代码示例来源:origin: shrinkwrap/shrinkwrap
@Test
public void getRoot() {
final Path path = fileSystem.getPath("/someNode");
final Path root = path.getRoot();
Assert.assertEquals("Did not return correct root", root.toString(), "/");
}
代码示例来源:origin: shrinkwrap/shrinkwrap
@Test
public void getRootFromRelative() {
final Path path = fileSystem.getPath("someNode");
final Path root = path.getRoot();
Assert.assertNull("Relative path should have null root", root);
}
内容来源于网络,如有侵权,请联系作者删除!