@Immutable public final class FsNodePath extends Object implements Serializable, Comparable<FsNodePath>
URI
and decompose it
into a file system mount point
and
node name.
A path adds the following syntax constraints to a
Uniform Resource Identifier
:
"!/"
.
The part up to the last mount point separator is parsed
according to the syntax constraints for an FsMountPoint
and set
as the value of the mountPoint
property.
The part after the last mount point separator is parsed
according to the syntax constraints for an FsNodeName
and set
as the value of the node name property.
"."
,
parsed according to the syntax constraints for an FsMountPoint
and set as the value of the mountPoint
property.
The URI relativized to this mount point is parsed according to the
syntax constraints for an FsNodeName
and set as the value of
the node name property.
mountPoint
property
is set to null
and the URI is parsed according to the syntax
constraints for an FsNodeName
and set as the value of the
node name property.
jar:<url>!/<node>
, these constraints
build a close subset of the syntax allowed by a
JarURLConnection
.
Examples for valid node path URIs:
uri property |
mountPoint URI |
nodeName URI |
---|---|---|
foo |
(null) | foo |
foo:/bar |
foo:/ |
bar |
foo:/bar/ |
foo:/bar |
(empty - not null) |
foo:bar:/baz!/bang |
foo:bar:/baz!/ |
bang |
Examples for invalid node path URIs:
URI | Issue |
---|---|
/foo |
leading slash separator not allowed if URI is not absolute |
foo/ |
trailing slash separator not allowed if URI is not absolute |
foo:bar |
missing mount point separator in opaque URI |
foo:bar:baz:/bang!/boom |
dito for bar:baz:/bang |
For any path p
, it's generally true that
new FsNodePath(p.getUri()).equals(p)
.
Furthermore, it's generally true that
new FsNodePath(p.getMountPoint(), p.getNodeName()).equals(p)
.
This class supports serialization with both
ObjectOutputStream
and XMLEncoder
.
FsMountPoint
,
FsNodeName
,
FsScheme
,
Serialized FormConstructor and Description |
---|
FsNodePath(File file)
Equivalent to
new FsNodePath(file.toURI(), FsUriModifier.CANONICALIZE) . |
FsNodePath(FsMountPoint mountPoint,
FsNodeName nodeName)
Constructs a new path by composing its URI from the given nullable mount
point and node name.
|
FsNodePath(URI uri)
Equivalent to
new FsNodePath(uri, FsUriModifier.NULL) . |
FsNodePath(URI uri,
FsUriModifier modifier)
Constructs a new path by parsing the given URI.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(FsNodePath that)
Implements a natural ordering which is consistent with
equals(Object) . |
static FsNodePath |
create(URI uri)
Equivalent to
create(uri, FsUriModifier.NULL) . |
static FsNodePath |
create(URI uri,
FsUriModifier modifier)
Constructs a new path by parsing the given URI.
|
boolean |
equals(Object that)
Returns
true iff the given object is a path name and its URI
equals the URI of this path name. |
FsMountPoint |
getMountPoint()
Returns the mount point component or
null iff this path's
URI is not absolute. |
FsNodeName |
getNodeName()
Returns the node name component.
|
URI |
getUri()
Returns the URI for this node path.
|
int |
hashCode()
Returns a hash code which is consistent with
equals(Object) . |
FsNodePath |
resolve(FsNodeName nodeName)
Resolves the given node name against this path.
|
URI |
toHierarchicalUri()
Returns a URI which is recursively transformed from the URI of this
path so that it's absolute and hierarchical.
|
String |
toString()
Equivalent to calling
URI.toString() on getUri() . |
public FsNodePath(File file)
new FsNodePath(file.toURI(), FsUriModifier.CANONICALIZE)
.
Note that this constructor is expected not to throw any exceptions.public FsNodePath(@CheckForNull FsMountPoint mountPoint, FsNodeName nodeName)
mountPoint
- the nullable mount point
.nodeName
- the node name
.@ConstructorProperties(value="uri") public FsNodePath(URI uri) throws URISyntaxException
new FsNodePath(uri, FsUriModifier.NULL)
.URISyntaxException
public FsNodePath(URI uri, FsUriModifier modifier) throws URISyntaxException
uri
- the non-null
URI
.modifier
- the URI modifier.URISyntaxException
- if uri
does not conform to the
syntax constraints for paths.public int compareTo(FsNodePath that)
equals(Object)
.compareTo
in interface Comparable<FsNodePath>
public static FsNodePath create(URI uri)
create(uri, FsUriModifier.NULL)
.public static FsNodePath create(URI uri, FsUriModifier modifier)
new FsNodePath(uri, modifier)
and wraps any thrown URISyntaxException
in an
IllegalArgumentException
.uri
- the URI
.modifier
- the URI modifier.IllegalArgumentException
- if uri
does not conform to the
syntax constraints for paths.public boolean equals(@CheckForNull Object that)
true
iff the given object is a path name and its URI
equals
the URI of this path name.
Note that this ignores the mount point and node name.@Nullable public FsMountPoint getMountPoint()
null
iff this path's
URI
is not absolute.public FsNodeName getNodeName()
null
.public URI getUri()
public int hashCode()
equals(Object)
.public FsNodePath resolve(FsNodeName nodeName)
nodeName
- a node name relative to this path.public URI toHierarchicalUri()
For example, the path URIs zip:file:/archive!/node
and
tar:file:/archive!/node
would both produce the hierarchical URI
file:/archive/node
.
public String toString()
URI.toString()
on getUri()
.Copyright © 2005–2018 Schlichtherle IT Services. All rights reserved.