@Immutable @DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) 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 Form| Modifier and Type | Field and Description |
|---|---|
private static URI |
DOT_URI |
private FsEntryName |
entryName |
private URI |
hierarchical |
private FsMountPoint |
mountPoint |
private static long |
serialVersionUID |
private URI |
uri |
| Constructor 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(String uri)
Deprecated.
This constructor does not quote characters with a special
meaning in a URI - use the constructor variant with the URI
parameter instead.
|
FsPath(String uri,
FsUriModifier modifier)
Deprecated.
This constructor does not quote characters with a special
meaning in a URI - use the constructor variant with the URI
parameter instead.
|
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(String uri)
Deprecated.
This method does not quote characters with a special meaning
in a URI - use the method variant with the URI parameter
instead.
|
static FsPath |
create(String uri,
FsUriModifier modifier)
Deprecated.
This method does not quote characters with a special meaning
in a URI - use the method variant with the URI parameter
instead.
|
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.
|
URI |
getHierarchicalUri()
Deprecated.
|
FsMountPoint |
getMountPoint()
Returns the mount point component or
null iff this path's
URI is not absolute. |
URI |
getUri()
Deprecated.
|
int |
hashCode()
Returns a hash code which is consistent with
equals(Object). |
private boolean |
invariants() |
private void |
parse(URI uri,
FsUriModifier modifier) |
private static String |
quote(Object s) |
private void |
readObject(ObjectInputStream in) |
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.
|
private void |
writeObject(ObjectOutputStream out) |
private static final long serialVersionUID
private static final URI DOT_URI
private URI uri
@Nullable private transient FsMountPoint mountPoint
private transient FsEntryName entryName
@Nullable private transient volatile URI hierarchical
@Deprecated public FsPath(String uri) throws URISyntaxException
new FsPath(uri, FsUriModifier.NULL).URISyntaxException@Deprecated public FsPath(String uri, FsUriModifier modifier) throws URISyntaxException
new URI(uri) and parsing the resulting URI.uri - the URI string representation.modifier - the URI modifier.URISyntaxException - if uri does not conform to the
syntax constraints for paths.public FsPath(File file)
new FsPath(file.toURI(), FsUriModifier.CANONICALIZE).
Note that this constructor is expected not to throw any exceptions.public FsPath(URI uri) throws URISyntaxException
new FsPath(uri, FsUriModifier.NULL).URISyntaxExceptionpublic 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 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.@Deprecated public static FsPath create(String uri)
create(uri, FsUriModifier.NULL).@Deprecated public static FsPath create(String uri, FsUriModifier modifier)
new FsPath(uri, modifier)
and wraps any thrown URISyntaxException in an
IllegalArgumentException.uri - the URI string representation.modifier - the URI modifier.IllegalArgumentException - if uri does not conform to the
syntax constraints for paths.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.private void writeObject(ObjectOutputStream out) throws IOException
IOExceptionprivate void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
IOExceptionClassNotFoundExceptionprivate void parse(URI uri, FsUriModifier modifier) throws URISyntaxException
URISyntaxExceptionprivate boolean invariants()
public URI toUri()
@Deprecated public URI getUri()
toUri()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.
@Deprecated public URI getHierarchicalUri()
toHierarchicalUri()@Nullable public FsMountPoint getMountPoint()
null iff this path's
URI is not absolute.public FsEntryName getEntryName()
null.public FsPath resolve(FsEntryName entryName)
entryName - an entry name relative to this path.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 int compareTo(FsPath that)
equals(Object).compareTo in interface Comparable<FsPath>public int hashCode()
equals(Object).public String toString()
URI.toString() on toUri().Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.