@Immutable public final class FsPath extends Object implements Serializable, Comparable<FsPath>
URI
and decompose it
into a mount point
of a file system and its
relative entry 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 FsEntryName
and set
as the value of the entryName
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 FsEntryName
and set as the value of
the entryName
property.
mountPoint
property
is set to null
and the URI is parsed according to the syntax
constraints for an FsEntryName
and set as the value of the
entryName
property.
jar:<url>!/<entry>
, these constraints
build a close subset of the syntax allowed by a
JarURLConnection
.
Examples for valid path URIs are:
uri property |
mountPoint URI |
entryName 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 path URIs are:
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 FsPath(p.toUri()).equals(p)
.
Furthermore, it's generally true that
new FsPath(p.getMountPoint(), p.getEntryName()).equals(p)
.
This class supports serialization with both
ObjectOutputStream
and XMLEncoder
.
FsMountPoint
,
FsEntryName
,
FsScheme
,
Serialized FormConstructor and Description |
---|
FsPath(File file)
Equivalent to
new FsPath(file.toURI(), FsUriModifier.CANONICALIZE) . |
FsPath(FsMountPoint mountPoint,
FsEntryName entryName)
Constructs a new path by composing its URI from the given nullable mount
point and entry name.
|
FsPath(URI uri)
Equivalent to
new FsPath(uri, FsUriModifier.NULL) . |
FsPath(URI uri,
FsUriModifier modifier)
Constructs a new path by parsing the given URI.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(FsPath that)
Implements a natural ordering which is consistent with
equals(Object) . |
static FsPath |
create(URI uri)
Equivalent to
create(uri, FsUriModifier.NULL) . |
static FsPath |
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. |
FsEntryName |
getEntryName()
Returns the entry name component.
|
FsMountPoint |
getMountPoint()
Returns the mount point component or
null iff this path's
URI is not absolute. |
int |
hashCode()
Returns a hash code which is consistent with
equals(Object) . |
FsPath |
resolve(FsEntryName entryName)
Resolves the given entry 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 toUri() . |
URI |
toUri()
Returns the URI for this path.
|
public FsPath(File file)
new FsPath(file.toURI(), FsUriModifier.CANONICALIZE)
.
Note that this constructor is expected not to throw any exceptions.public FsPath(@CheckForNull FsMountPoint mountPoint, FsEntryName entryName)
mountPoint
- the nullable mount point
.entryName
- the entry name
.URISyntaxException
- if the composed path URI would not conform
to the syntax constraints for paths.public FsPath(URI uri) throws URISyntaxException
new FsPath(uri, FsUriModifier.NULL)
.URISyntaxException
public FsPath(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(FsPath that)
equals(Object)
.compareTo
in interface Comparable<FsPath>
public static FsPath create(URI uri)
create(uri, FsUriModifier.NULL)
.public static FsPath create(URI uri, FsUriModifier modifier)
new FsPath(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 entry name.public FsEntryName getEntryName()
null
.@Nullable public FsMountPoint getMountPoint()
null
iff this path's
URI
is not absolute.public int hashCode()
equals(Object)
.public FsPath resolve(FsEntryName entryName)
entryName
- an entry name relative to this path.public URI toHierarchicalUri()
For example, the path URIs zip:file:/archive!/entry
and
tar:file:/archive!/entry
would both produce the hierarchical URI
file:/archive/entry
.
public String toString()
URI.toString()
on toUri()
.public URI toUri()
Copyright © 2005–2018 Schlichtherle IT Services. All rights reserved.