@Immutable @DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) public final class FsPath extends java.lang.Object implements java.io.Serializable, java.lang.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 java.net.URI |
DOT |
private FsEntryName |
entryName |
private java.net.URI |
hierarchical |
private FsMountPoint |
mountPoint |
private static long |
serialVersionUID |
private java.net.URI |
uri |
| Constructor and Description |
|---|
FsPath(java.io.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(java.lang.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(java.lang.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(java.net.URI uri)
Equivalent to
new FsPath(uri, FsUriModifier.NULL). |
FsPath(java.net.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(java.lang.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(java.lang.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(java.net.URI uri)
Equivalent to
create(uri, FsUriModifier.NULL). |
static FsPath |
create(java.net.URI uri,
FsUriModifier modifier)
Constructs a new path by parsing the given URI.
|
boolean |
equals(java.lang.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.
|
java.net.URI |
getHierarchicalUri()
Deprecated.
|
FsMountPoint |
getMountPoint()
Returns the mount point component or
null iff this path's
URI is not absolute. |
java.net.URI |
getUri()
Deprecated.
|
int |
hashCode()
Returns a hash code which is consistent with
equals(Object). |
private boolean |
invariants() |
private void |
parse(java.net.URI uri,
FsUriModifier modifier) |
private void |
readObject(java.io.ObjectInputStream in) |
FsPath |
resolve(FsEntryName entryName)
Resolves the given entry name against this path.
|
private static java.lang.String |
toDecodedUri(FsEntryName entryName) |
java.net.URI |
toHierarchicalUri()
Returns a URI which is recursively transformed from the URI of this
path so that it's absolute and hierarchical.
|
java.lang.String |
toString()
Equivalent to calling
URI.toString() on toUri(). |
java.net.URI |
toUri()
Returns the URI for this path.
|
private void |
writeObject(java.io.ObjectOutputStream out) |
private static final long serialVersionUID
private static final java.net.URI DOT
private java.net.URI uri
@Nullable private transient FsMountPoint mountPoint
private transient FsEntryName entryName
@Nullable private transient volatile java.net.URI hierarchical
@Deprecated
public FsPath(java.lang.String uri)
throws java.net.URISyntaxException
new FsPath(uri, FsUriModifier.NULL).java.net.URISyntaxException@Deprecated
public FsPath(java.lang.String uri,
FsUriModifier modifier)
throws java.net.URISyntaxException
new URI(uri)
and parsing the resulting URI.uri - the URI string representation.modifier - the URI modifier.java.net.URISyntaxException - if uri does not conform to the
syntax constraints for paths.public FsPath(java.io.File file)
new FsPath(file.toURI(), FsUriModifier.CANONICALIZE).
Note that this constructor is expected not to throw any exceptions.public FsPath(java.net.URI uri)
throws java.net.URISyntaxException
new FsPath(uri, FsUriModifier.NULL).java.net.URISyntaxExceptionpublic FsPath(java.net.URI uri,
FsUriModifier modifier)
throws java.net.URISyntaxException
uri - the non-null URI.modifier - the URI modifier.java.net.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.java.net.URISyntaxException - if the composed path URI would not conform
to the syntax constraints for paths.@Deprecated public static FsPath create(java.lang.String uri)
create(uri, FsUriModifier.NULL).@Deprecated public static FsPath create(java.lang.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.java.lang.IllegalArgumentException - if uri does not conform to the
syntax constraints for paths.public static FsPath create(java.net.URI uri)
create(uri, FsUriModifier.NULL).public static FsPath create(java.net.URI uri, FsUriModifier modifier)
new FsPath(uri, modifier)
and wraps any thrown URISyntaxException in an
IllegalArgumentException.uri - the URI.modifier - the URI modifier.java.lang.IllegalArgumentException - if uri does not conform to the
syntax constraints for paths.private void writeObject(java.io.ObjectOutputStream out)
throws java.io.IOException
java.io.IOExceptionprivate void readObject(java.io.ObjectInputStream in)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOExceptionjava.lang.ClassNotFoundExceptionprivate void parse(java.net.URI uri,
FsUriModifier modifier)
throws java.net.URISyntaxException
java.net.URISyntaxExceptionprivate static java.lang.String toDecodedUri(FsEntryName entryName)
private boolean invariants()
public java.net.URI toUri()
@Deprecated public java.net.URI getUri()
toUri()public java.net.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 java.net.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
java.lang.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.equals in class java.lang.Objectpublic int compareTo(FsPath that)
equals(Object).compareTo in interface java.lang.Comparable<FsPath>public int hashCode()
equals(Object).hashCode in class java.lang.Objectpublic java.lang.String toString()
URI.toString() on toUri().toString in class java.lang.ObjectCopyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.