public final class UniformPath extends Object implements Iterable<UniformPath>, Comparable<UniformPath>
Path
-like object that defines a file system independent path syntax
and is not associated with any FileSystem
instance.
Uniform paths use the following UNIX-like syntax:
[[//root]/]path/to/file/or/directory
where []
indicates an optional component and /
serves as the path separator. All names are case-sensitive.
If the root component is present, the path is absolute. For single-root file
systems, the root prefix //
and the root name are omitted and
the path starts with a single forward slash. For multi-root file system, the
path starts with the root prefix followed by the name of the root and a
single forward slash. Root names that contain the path separator (/
)
are not allowed.
UniformPath
s can be converted to standard Path
s using the
toPath
method.
Modifier and Type | Method and Description |
---|---|
int |
compareTo(UniformPath other) |
boolean |
endsWith(String other) |
boolean |
endsWith(UniformPath other) |
boolean |
equals(Object obj) |
static UniformPath |
fromPath(Path path)
Converts the specified
Path into a UniformPath . |
static UniformPath |
get(Iterable<String> components)
Converts a sequence of strings that form a path string when joined to a
UniformPath . |
static UniformPath |
get(String first,
String... more)
Converts a path string, or a sequence of strings that form a path string
when joined, to a
UniformPath . |
UniformPath |
getFileName() |
UniformPath |
getName(int index) |
int |
getNameCount() |
UniformPath |
getParent() |
UniformPath |
getRoot() |
int |
hashCode() |
boolean |
isAbsolute() |
Iterator<UniformPath> |
iterator() |
UniformPath |
normalize() |
UniformPath |
relativize(UniformPath other) |
UniformPath |
resolve(String other) |
UniformPath |
resolve(UniformPath other) |
UniformPath |
resolveSibling(String other) |
UniformPath |
resolveSibling(UniformPath other) |
boolean |
startsWith(String other) |
boolean |
startsWith(UniformPath other) |
UniformPath |
subpath(int beginIndex,
int endIndex) |
Path |
toPath()
Converts this uniform path to a real
Path on the default file
system. |
Path |
toPath(FileSystem fs)
Converts this uniform path to a real
Path on the given file
system. |
String |
toString() |
public static UniformPath get(String first, String... more)
UniformPath
.first
- the path string or initial part of the path stringmore
- additional strings to join to form the path stringpublic static UniformPath get(Iterable<String> components)
UniformPath
.components
- the components to join to form the path stringpublic static UniformPath fromPath(Path path)
Path
into a UniformPath
.
For any path p
, the following relationship will always hold:
UniformPath.fromPath(p).toPath(p.getFileSystem()).equals(p)
path
- the path to convertUniformPath
that is equivalent to the given pathIllegalArgumentException
- if any path segment contains the uniform
path separatorpublic boolean isAbsolute()
public UniformPath getRoot()
public UniformPath getFileName()
public UniformPath getParent()
public int getNameCount()
public UniformPath getName(int index)
public UniformPath subpath(int beginIndex, int endIndex)
public boolean startsWith(UniformPath other)
public boolean startsWith(String other)
public boolean endsWith(UniformPath other)
public boolean endsWith(String other)
public UniformPath normalize()
public UniformPath resolve(UniformPath other)
public UniformPath resolve(String other)
public UniformPath resolveSibling(UniformPath other)
public UniformPath resolveSibling(String other)
public UniformPath relativize(UniformPath other)
public Iterator<UniformPath> iterator()
iterator
in interface Iterable<UniformPath>
public Path toPath()
Path
on the default file
system.toPath(FileSystem)
public Path toPath(FileSystem fs)
Path
on the given file
system.
If this path is a relative path, each segment is passed as a separate
argument to the file system's
getPath
method. If this
path is an absolute path, a relative path is constructed as described
then resolved against a root path obtained using the following method:
IllegalArgumentException
fs
- the FileSystem
on which to create a pathIllegalArgumentException
- if this is an absolute path and the
given file system does not have a matching rootpublic int compareTo(UniformPath other)
compareTo
in interface Comparable<UniformPath>