@Immutable public final class TPath extends Object implements Path, TRex
Path
implementation for use with NIO.2.
Applications should directly instantiate this class to overcome the
restrictions of the file system
provider service location in the NIO.2 API for JSE 7.
Once created, it's safe to use TPath
instances polymorphically as
Path
instances.
Objects of this class are immutable and inherently volatile because all virtual file system state is managed by the TrueVFS Kernel module.
You should never use object identity ('==') to test for equality of objects
of this class with another object.
Use the method equals(Object)
instead.
Unless otherwise noted, you should not assume that calling the same method on an instance of this class multiple times will return the same object.
Unless otherwise noted, when an instance of this class is created, the
resulting path name gets scanned for prospective archive files using the
current archive detector TConfig.current().getArchiveDetector()
.
To change this, wrap the object creation in a code block which
pushes
a temporary configuration on the inheritbale
thread local stack of configurations as follows:
// Create reference to the current directory.
TPath directory = new TPath("");
// This is how you would detect a prospective archive file, supposing
// the JAR of the module TrueVFS Driver ZIP is present on the run time
// class path.
TPath archive = directory.resolve("archive.zip");
TPath file;
try (TConfig config = TConfig.open()) {
config.setArchiveDetector(TArchiveDetector.NULL);
// Ignore prospective archive file here.
file = directory.resolve("archive.zip");
}
// Once created, the prospective archive file detection does not change
// because a TPath is immutable.
assert archive.getArchiveDetector() == TArchiveDetector.ALL;
assert archive.isArchive();
assert file.getArchiveDetector() == TArchiveDetector.NULL;
assert !file.isArchive();
Mind that you should either use archive
or file
from the
previous example to do any subsequent I/O - but not both - so that you don't
bypass or corrupt the state which gets implicitly associated with any
archive file by the TrueVFS Kernel module!
Constructor and Description |
---|
TPath(File file)
Constructs a new path from the given file.
|
TPath(Path path)
Constructs a new path from the given path.
|
TPath(String first,
String... more)
Constructs a new path from the given path strings.
|
TPath(URI name)
Constructs a new path from the given hierarchical URI.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Path other)
The natural ordering imposed by this implementation is identical to the
natural ordering of path's
name . |
boolean |
endsWith(Path that) |
boolean |
endsWith(String other) |
boolean |
equals(Object other)
This path is considered equal to the given
other object
if and only if the other object is identical to this object or if the
other object is a TPath object with a
file system which is considered
equal to this path's file system and
a name which is considered
equal to this path's name. |
TArchiveDetector |
getArchiveDetector()
Returns the
TArchiveDetector which was used to detect any
archive files in the path name of this object at construction time. |
TPath |
getFileName() |
TFileSystem |
getFileSystem()
Returns the
TFileSystem for this path. |
FsMountPoint |
getMountPoint()
Returns the file system mount point for this path.
|
TPath |
getName(int index) |
int |
getNameCount() |
FsNodeName |
getNodeName()
Returns the file system entry name.
|
FsNodePath |
getNodePath()
Returns the file system node path with an absolute URI.
|
TPath |
getParent() |
TPath |
getRoot() |
URI |
getUri()
Returns the absolute URI for this object.
|
int |
hashCode()
Returns a hash code which is consistent with
equals(Object) . |
boolean |
isAbsolute() |
boolean |
isArchive()
Returns
true if and only if this TPath addresses an
archive file. |
boolean |
isEntry()
Returns
true if and only if this TPath addresses an
entry located within an archive file. |
Iterator<Path> |
iterator() |
TPath |
normalize() |
WatchKey |
register(WatchService watcher,
WatchEvent.Kind<?>... events) |
WatchKey |
register(WatchService watcher,
WatchEvent.Kind<?>[] events,
WatchEvent.Modifier... modifiers) |
TPath |
relativize(Path other) |
TPath |
resolve(Path other) |
TPath |
resolve(String other) |
TPath |
resolveSibling(Path other) |
TPath |
resolveSibling(String other) |
boolean |
startsWith(Path that) |
boolean |
startsWith(String other) |
TPath |
subpath(int beginIndex,
int endIndex) |
TPath |
toAbsolutePath() |
TFile |
toFile()
Returns a new
TFile object for this path. |
TPath |
toNonArchivePath()
Returns a path object for the same path name, but does not detect any
archive file name patterns in the last path name segment.
|
TPath |
toPath()
Returns a path representation of this object.
|
TPath |
toRealPath(LinkOption... options) |
String |
toString() |
URI |
toUri() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public TPath(File file)
This constructor is required for interoperability with the TFile
class because it does not support TFile.toPath()
.
If file
is an instance of TFile
, its
archive detector and
file system node path get shared with
this instance.
Otherwise, this constructor scans the path name
of the file to detect prospective archive files using the
current archive detector TConfig.current().getArchiveDetector()
.
On all platforms:
Path path = new TPath(new File("app.war/WEB-INF/lib", "lib.jar/META-INF/MANIFEST.MF"));
On POSIX platforms (Unix, Linux, Mac OS X):
File
:Path path = new TPath(new File("/home/christian/archive.zip"));
TFile
:Path path = new TPath(new TFile("/home/christian/archive.zip"));
On the Windows platform:
File
:Path path = new TPath(new File("c:\home\christian\archive.zip"));
TFile
:Path path = new TPath(new TFile("c:\home\christian\archive.zip"));
file
- a file.
If this is an instance of TFile
, its
archive detector and
file system node path get shared
with this instance.public TPath(Path path)
This constructor scans the path name
of the
given path to detect prospective archive files using the
current archive detector TConfig.current().getArchiveDetector()
.
On all platforms:
Path path = new TPath(Paths.current("app.war/WEB-INF/lib", "lib.jar/META-INF/MANIFEST.MF"));
path
- a path.public TPath(String first, String... more)
The supported path name separators are "File.separator
" and
"/
".
Any trailing separators in the resulting path name get discarded.
This constructor scans the path name resulting
from the segment parameters to detect prospective archive files using
the current archive detector TConfig.current().getArchiveDetector()
.
On all platforms:
Path path = new TPath("app.war/WEB-INF/lib", "lib.jar/META-INF/MANIFEST.MF");
On POSIX platforms (Unix, Linux, Mac OS X):
Path path = new TPath("/home/christian/archive.zip");
On the Windows platform:
Path path = new TPath("app.war\WEB-INF\lib", "lib.jar\META-INF\MANIFEST.MF");
Path path = new TPath("c:\UsErS\cHrIsTiAn\ArChIvE.zIp");
Path path = new TPath("//host", "share", "archive.zip");
Path path = new TPath("\\host/share\archive.zip");
first
- the first sub path string.more
- optional sub path strings.public TPath(URI name)
If the scheme component of the URI is undefined
and the scheme specific part does
not start with a "/
", then the URI gets resolved against the
"file:
" based URI for the current directory in the platform file
system.
Otherwise, if the scheme component is undefined, then the URI gets
resolved against the URI "file:/
".
This constructor scans the path component of
the URI to detect prospective archive files using the
current archive detector TConfig.current().getArchiveDetector()
.
On all platforms:
Path path = new TPath(new URI("app.war/WEB-INF/lib/lib.jar/META-INF/MANIFEST.MF"));
Path path = new TPath(new URI("http://acme.com/download/everything.tar.gz/README.TXT"));
On POSIX platforms (Unix, Linux, Mac OS X):
Path path = new TPath(new URI("/home/christian/archive.zip"));
Path path = new TPath(new URI("file:/home/christian/archive.zip"));
On the Windows platform:
Path path = new TPath(new URI("c%3A/Users/christian/archive.zip"));
Path path = new TPath(new URI("file:/c:/Users/christian/archive.zip"));
Path path = new TPath(new URI("//host/share/archive.zip"));
Path path = new TPath(new URI("file://host/share/archive.zip"));
name
- the path name.
This must be a hierarchical URI with an undefined fragment
component.
Any trailing separators in the path component get discarded.IllegalArgumentException
- if the preconditions for the parameter
do not hold.public int compareTo(Path other)
name
.
On Windows, case is ignored when comparing the path names.compareTo
in interface Comparable<Path>
compareTo
in interface Path
public boolean equals(Object other)
other
object
if and only if the other object is identical to this object or if the
other object is a TPath
object with a
file system
which is considered
equal
to this path's file system and
a name
which is considered
equal
to this path's name.
On Windows, case is ignored when comparing the path names.public TArchiveDetector getArchiveDetector()
TRex
TArchiveDetector
which was used to detect any
archive files in the path name of this object at construction time.getArchiveDetector
in interface TRex
TArchiveDetector
which was used to detect any
archive files in the path name of this object at construction
time.@Nullable public TPath getFileName()
getFileName
in interface Path
public TFileSystem getFileSystem()
TFileSystem
for this path.
Multiple invocations of this method will return the same object.getFileSystem
in interface Path
TFileSystem
for this path.public FsMountPoint getMountPoint()
TRex
getMountPoint
in interface TRex
public int getNameCount()
getNameCount
in interface Path
public FsNodeName getNodeName()
TRex
getNodeName
in interface TRex
public FsNodePath getNodePath()
TRex
getNodePath
in interface TRex
public URI getUri()
TRex
public int hashCode()
equals(Object)
.hashCode
in interface Path
hashCode
in class Object
equals(Object)
.public boolean isAbsolute()
isAbsolute
in interface Path
public boolean isArchive()
true
if and only if this TPath
addresses an
archive file.
Whether or not this is true solely depends on the
TArchiveDetector
which was used to construct this TPath
- no file system tests are performed by this method!true
if and only if this TPath
addresses an
archive file.isEntry()
public boolean isEntry()
true
if and only if this TPath
addresses an
entry located within an archive file.
Whether or not this is true solely depends on the
TArchiveDetector
which was used to construct this TPath
- no file system tests are performed by this method!true
if and only if this TPath
addresses an
entry located within an archive file.isArchive()
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws IOException
register
in interface Path
register
in interface Watchable
UnsupportedOperationException
- alwaysIOException
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException
register
in interface Path
register
in interface Watchable
UnsupportedOperationException
- alwaysIOException
public TPath relativize(Path other)
relativize
in interface Path
public TPath resolveSibling(Path other)
resolveSibling
in interface Path
public TPath resolveSibling(String other)
resolveSibling
in interface Path
public boolean startsWith(Path that)
startsWith
in interface Path
public boolean startsWith(String other)
startsWith
in interface Path
public TPath toAbsolutePath()
toAbsolutePath
in interface Path
public TFile toFile()
TFile
object for this path.
If this path was constructed by the
file constructor
, then the returned new
TFile
object compares equal
with
that file object, even if it was a plain File
object.@ExpertFeature(level=INTERMEDIATE, value=INJECTING_A_DIFFERENT_DETECTOR_FOR_THE_SAME_PATH_MAY_CORRUPT_DATA) public TPath toNonArchivePath()
Warning: Doing I/O on the returned path object will yield inconsistent results and may even cause loss of data if the last path name segment addresses an archive file which is currently mounted by the TrueVFS Kernel!
TFileSystem.close()
,
TVFS.umount()
public TPath toPath()
TRex
public TPath toRealPath(LinkOption... options) throws IOException
toRealPath
in interface Path
IOException
public String toString()
Copyright © 2005–2018 Schlichtherle IT Services. All rights reserved.