Path implements IOReadableWritable, Serializable { public URI toUri() { return uri; } Path();  Path(URI uri);  Path(String parent, String child);  Path(Path parent, String child);  Path(String parent, Path child);  Path(Path parent, Path child);  Path(String pathString);  Path(String scheme, String authority, String path); URI toUri(); FileSystem getFileSystem(); boolean isAbsolute(); String getName(); Path getParent(); Path suffix(String suffix); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); int compareTo(Object o); int depth(); Path makeQualified(FileSystem fs); @Override void read(DataInputView in); @Override void write(DataOutputView out); static final String SEPARATOR; static final char SEPARATOR_CHAR; static final String CUR_DIR; }
@Test public void testPathFromString() { Path p = new Path("/my/path"); assertEquals("/my/path", p.toUri().getPath()); assertNull(p.toUri().getScheme()); p = new Path("/my/path/"); assertEquals("/my/path", p.toUri().getPath()); assertNull(p.toUri().getScheme()); p = new Path("/my assertEquals("/my/path", p.toUri().getPath()); assertNull(p.toUri().getScheme()); p = new Path("/my assertEquals("/my/path/a", p.toUri().getPath()); assertNull(p.toUri().getScheme()); p = new Path("\\my\\path\\\\a\\\\\\"); assertEquals("/my/path/a", p.toUri().getPath()); assertNull(p.toUri().getScheme()); p = new Path("/my/path/ "); assertEquals("/my/path", p.toUri().getPath()); assertNull(p.toUri().getScheme()); p = new Path("hdfs: assertEquals("/my/path", p.toUri().getPath()); assertEquals("hdfs", p.toUri().getScheme()); p = new Path("hdfs: assertEquals("/my/path", p.toUri().getPath()); assertEquals("hdfs", p.toUri().getScheme()); p = new Path("file: assertEquals("/my/path", p.toUri().getPath()); assertEquals("file", p.toUri().getScheme()); p = new Path("C:/my/windows/path"); assertEquals("/C:/my/windows/path", p.toUri().getPath()); p = new Path("file:/C:/my/windows/path"); assertEquals("/C:/my/windows/path", p.toUri().getPath()); try { new Path((String)null); fail(); } catch(Exception e) { } try { new Path(""); fail(); } catch(Exception e) { } try { new Path(" "); fail(); } catch(Exception e) { } }
@Test public void testParsing() { URI u; String scheme = "hdfs"; String authority = "localhost:8000"; String path = "/test/test"; u = new Path(scheme + ": assertEquals(scheme, u.getScheme()); assertEquals(authority, u.getAuthority()); assertEquals(path, u.getPath()); u = new Path(scheme + ": assertEquals(scheme, u.getScheme()); assertEquals(null, u.getAuthority()); assertEquals(path, u.getPath()); u = new Path(scheme + ":" + path).toUri(); assertEquals(scheme, u.getScheme()); assertEquals(null, u.getAuthority()); assertEquals(path, u.getPath()); u = new Path(scheme + ":/" + path).toUri(); assertEquals(scheme, u.getScheme()); assertEquals("test", u.getAuthority()); assertEquals("/test", u.getPath()); u = new Path(scheme + ": assertEquals("hdfs", u.getScheme()); assertEquals(null, u.getAuthority()); assertEquals(path, u.getPath()); }