Path implements Comparable, Serializable, ObjectInputValidation { @Override public String toString() { StringBuilder buffer = new StringBuilder(); if (uri.getScheme() != null) { buffer.append(uri.getScheme()); buffer.append(":"); } if (uri.getAuthority() != null) { buffer.append(" buffer.append(uri.getAuthority()); } if (uri.getPath() != null) { String path = uri.getPath(); if (path.indexOf('/')==0 && hasWindowsDrive(path) && uri.getScheme() == null && uri.getAuthority() == null) path = path.substring(1); buffer.append(path); } if (uri.getFragment() != null) { buffer.append("#"); buffer.append(uri.getFragment()); } return buffer.toString(); } Path(String parent, String child);  Path(Path parent, String child);  Path(String parent, Path child);  Path(Path parent, Path child);  Path(String pathString);  Path(URI aUri);  Path(String scheme, String authority, String path); static Path getPathWithoutSchemeAndAuthority(Path path); static Path mergePaths(Path path1, Path path2); static boolean isWindowsAbsolutePath(final String pathString,
                                              final boolean slashed); URI toUri(); FileSystem getFileSystem(Configuration conf); boolean isAbsoluteAndSchemeAuthorityNull(); boolean isUriPathAbsolute(); boolean isAbsolute(); boolean isRoot(); String getName(); Path getParent(); Path suffix(String suffix); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(Object o); int depth(); @Deprecated Path makeQualified(FileSystem fs); @InterfaceAudience.LimitedPrivate({"HDFS", "MapReduce"}) Path makeQualified(URI defaultUri, Path workingDir ); @Override void validateObject(); void setScheme(String scheme); static final String SEPARATOR; static final char SEPARATOR_CHAR; static final String CUR_DIR; static final boolean WINDOWS; }
@Test (timeout = 30000) public void testToString() { toStringTest("/"); toStringTest("/foo"); toStringTest("/foo/bar"); toStringTest("foo"); toStringTest("foo/bar"); toStringTest("/foo/bar#boo"); toStringTest("foo/bar#boo"); boolean emptyException = false; try { toStringTest(""); } catch (IllegalArgumentException e) { emptyException = true; } assertTrue(emptyException); if (Path.WINDOWS) { toStringTest("c:"); toStringTest("c:/"); toStringTest("c:foo"); toStringTest("c:foo/bar"); toStringTest("c:foo/bar"); toStringTest("c:/foo/bar"); toStringTest("C:/foo/bar#boo"); toStringTest("C:foo/bar#boo"); } }
@Test (timeout = 30000) public void testNormalize() throws URISyntaxException { assertEquals("", new Path(".").toString()); assertEquals("..", new Path("..").toString()); assertEquals("/", new Path("/").toString()); assertEquals("/", new Path(" assertEquals("/", new Path(" assertEquals(" assertEquals(" assertEquals(" assertEquals("/foo", new Path("/foo/").toString()); assertEquals("/foo", new Path("/foo/").toString()); assertEquals("foo", new Path("foo/").toString()); assertEquals("foo", new Path("foo assertEquals("foo/bar", new Path("foo assertEquals("hdfs: new Path(new URI("hdfs: if (Path.WINDOWS) { assertEquals("c:/a/b", new Path("c:\\a\\b").toString()); } }
@Test (timeout = 30000) public void testDots() { assertEquals(new Path("/foo/bar/baz").toString(), "/foo/bar/baz"); assertEquals(new Path("/foo/bar", ".").toString(), "/foo/bar"); assertEquals(new Path("/foo/bar/../baz").toString(), "/foo/baz"); assertEquals(new Path("/foo/bar/./baz").toString(), "/foo/bar/baz"); assertEquals(new Path("/foo/bar/baz/../../fud").toString(), "/foo/fud"); assertEquals(new Path("/foo/bar/baz/.././../fud").toString(), "/foo/fud"); assertEquals(new Path("../../foo/bar").toString(), "../../foo/bar"); assertEquals(new Path(".././../foo/bar").toString(), "../../foo/bar"); assertEquals(new Path("./foo/bar/baz").toString(), "foo/bar/baz"); assertEquals(new Path("/foo/bar/../../baz/boo").toString(), "/baz/boo"); assertEquals(new Path("foo/bar/").toString(), "foo/bar"); assertEquals(new Path("foo/bar/../baz").toString(), "foo/baz"); assertEquals(new Path("foo/bar/../../baz/boo").toString(), "baz/boo"); assertEquals(new Path("/foo/bar", "baz/boo").toString(), "/foo/bar/baz/boo"); assertEquals(new Path("foo/bar/","baz/bud").toString(), "foo/bar/baz/bud"); assertEquals(new Path("/foo/bar","../../boo/bud").toString(), "/boo/bud"); assertEquals(new Path("foo/bar","../../boo/bud").toString(), "boo/bud"); assertEquals(new Path(".","boo/bud").toString(), "boo/bud"); assertEquals(new Path("/foo/bar/baz","../../boo/bud").toString(), "/foo/boo/bud"); assertEquals(new Path("foo/bar/baz","../../boo/bud").toString(), "foo/boo/bud"); assertEquals(new Path("../../","../../boo/bud").toString(), "../../../../boo/bud"); assertEquals(new Path("../../foo","../../../boo/bud").toString(), "../../../../boo/bud"); assertEquals(new Path("../../foo/bar","../boo/bud").toString(), "../../foo/boo/bud"); assertEquals(new Path("foo/bar/baz","../../..").toString(), ""); assertEquals(new Path("foo/bar/baz","../../../../..").toString(), "../.."); }
@Test (timeout = 5000) public void testWindowsPaths() throws URISyntaxException, IOException { assumeWindows(); assertEquals(new Path("c:\\foo\\bar").toString(), "c:/foo/bar"); assertEquals(new Path("c:/foo/bar").toString(), "c:/foo/bar"); assertEquals(new Path("/c:/foo/bar").toString(), "c:/foo/bar"); assertEquals(new Path("file: }
@Test (timeout = 30000) public void testScheme() throws java.io.IOException { assertEquals("foo:/bar", new Path("foo:/","/bar").toString()); assertEquals("foo: }