@Immutable @DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) public final class TPath extends Object implements java.nio.file.Path
Path implementation
based on the TrueZIP Kernel module.
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 TrueZIP 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
default archive detector.
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 TrueZIP Driver ZIP is present on the run time
// class path.
TPath archive = directory.resolve("archive.zip");
TPath file;
try (TConfig config = TConfig.push()) {
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 TrueZIP Kernel module!
| Modifier and Type | Class and Description |
|---|---|
private static class |
TPath.SegmentIterator |
private static class |
TPath.TPathComparator
The methods in this class use
getAddress(). |
private static class |
TPath.WindowsTPathComparator
The methods in this class use
getAddress(). |
| Modifier and Type | Field and Description |
|---|---|
private FsPath |
address |
private static TPath.TPathComparator |
COMPARATOR |
private TArchiveDetector |
detector |
private List<String> |
elements |
private TFileSystem |
fileSystem |
private Integer |
hashCode |
private URI |
name |
private String |
string |
| Modifier | Constructor and Description |
|---|---|
|
TPath(File file)
Constructs a new path from the given file.
|
|
TPath(java.nio.file.Path path)
Constructs a new path from the given path.
|
|
TPath(String first,
String... more)
Constructs a new path from the given path strings.
|
(package private) |
TPath(TFileSystem fileSystem,
String first,
String... more)
Constructs a new path from the given file system and sub path strings.
|
|
TPath(URI name)
Constructs a new path from the given hierarchical URI.
|
private |
TPath(URI name,
TArchiveDetector detector,
FsPath address) |
| Modifier and Type | Method and Description |
|---|---|
private static FsPath |
address(URI name,
TArchiveDetector detector) |
(package private) void |
checkAccess(java.nio.file.AccessMode... modes) |
int |
compareTo(java.nio.file.Path that)
The natural ordering imposed by this implementation is identical to the
natural ordering of path's
name. |
(package private) void |
createDirectory(java.nio.file.attribute.FileAttribute<?>... attrs) |
private static String |
cutLeadingSeparators(String p) |
(package private) static String |
cutTrailingSeparators(String p,
int o) |
(package private) void |
delete() |
boolean |
endsWith(java.nio.file.Path that) |
boolean |
endsWith(String other) |
boolean |
equals(Object that)
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. |
private FsPath |
getAddress()
Returns the file system path for this path with an absolute URI.
|
(package private) TArchiveDetector |
getArchiveDetector()
Returns the
TArchiveDetector used for scanning this path's
name for prospective archive files at construction
time. |
static TArchiveDetector |
getDefaultArchiveDetector()
Equivalent to
TConfig.get().getArchiveDetector(). |
private List<String> |
getElements()
Returns the segments of this path's
name. |
private List<String> |
getElements0() |
(package private) FsEntry |
getEntry() |
(package private) FsEntryName |
getEntryName()
Returns the file system entry name for this path.
|
(package private) <V extends java.nio.file.attribute.FileAttributeView> |
getFileAttributeView(Class<V> type,
java.nio.file.LinkOption... options) |
TPath |
getFileName() |
TFileSystem |
getFileSystem()
Returns the
TFileSystem for this path. |
private TFileSystem |
getFileSystem0() |
(package private) BitField<FsInputOption> |
getInputPreferences() |
(package private) InputSocket<?> |
getInputSocket(BitField<FsInputOption> options) |
(package private) FsMountPoint |
getMountPoint()
Returns the file system mount point for this path.
|
(package private) URI |
getName()
Returns the name of this path as a
URI. |
TPath |
getName(int index) |
int |
getNameCount() |
(package private) TPath |
getNonArchivePath() |
(package private) BitField<FsOutputOption> |
getOutputPreferences() |
(package private) OutputSocket<?> |
getOutputSocket(BitField<FsOutputOption> options,
Entry template) |
TPath |
getParent() |
TPath |
getRoot() |
int |
hashCode()
Returns a hash code which is consistent with
equals(Object). |
private boolean |
invariants()
Checks the invariants of this class and throws an AssertionError if
any is violated even if assertion checking is disabled.
|
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<java.nio.file.Path> |
iterator() |
(package private) BitField<FsInputOption> |
mapInput(java.nio.file.OpenOption... options) |
(package private) BitField<FsInputOption> |
mapInput(Set<? extends java.nio.file.OpenOption> options) |
(package private) BitField<FsOutputOption> |
mapOutput(java.nio.file.OpenOption... options) |
(package private) BitField<FsOutputOption> |
mapOutput(Set<? extends java.nio.file.OpenOption> options) |
private static URI |
name(String first,
String... more) |
private static URI |
name(URI uri) |
(package private) SeekableByteChannel |
newByteChannel(Set<? extends java.nio.file.OpenOption> options,
java.nio.file.attribute.FileAttribute<?>... attrs) |
(package private) java.nio.file.DirectoryStream<java.nio.file.Path> |
newDirectoryStream(java.nio.file.DirectoryStream.Filter<? super java.nio.file.Path> filter) |
(package private) InputStream |
newInputStream(java.nio.file.OpenOption... options) |
(package private) OutputStream |
newOutputStream(java.nio.file.OpenOption... options) |
TPath |
normalize() |
private static int |
prefixLength(String p) |
(package private) <A extends java.nio.file.attribute.BasicFileAttributes> |
readAttributes(Class<A> type,
java.nio.file.LinkOption... options) |
java.nio.file.WatchKey |
register(java.nio.file.WatchService watcher,
java.nio.file.WatchEvent.Kind<?>... events) |
java.nio.file.WatchKey |
register(java.nio.file.WatchService watcher,
java.nio.file.WatchEvent.Kind<?>[] events,
java.nio.file.WatchEvent.Modifier... modifiers) |
TPath |
relativize(java.nio.file.Path other) |
TPath |
resolve(java.nio.file.Path other) |
TPath |
resolve(String other) |
private TPath |
resolve(URI m) |
TPath |
resolveSibling(java.nio.file.Path other) |
TPath |
resolveSibling(String other) |
static void |
setDefaultArchiveDetector(TArchiveDetector detector)
Equivalent to
TConfig.get().setArchiveDetector(detector). |
boolean |
startsWith(java.nio.file.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 |
toRealPath(java.nio.file.LinkOption... options) |
String |
toString() |
private String |
toString0() |
URI |
toUri() |
private static final TPath.TPathComparator COMPARATOR
private final URI name
private final TArchiveDetector detector
private final FsPath address
@CheckForNull private volatile TFileSystem fileSystem
@CheckForNull private volatile String string
@CheckForNull private volatile Integer hashCode
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 default archive detector.
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.TPath(TFileSystem fileSystem, String first, String... more)
The supported path name separators are "File.separator" and
"/".
Any leading and 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 default archive detector.
fileSystem - the file system to access.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
default archive detector.
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 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 path get shared with this instance.
Otherwise, this constructor scans the path name
of the file to detect prospective archive files using the
default archive detector.
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
address get shared with this instance.public TPath(java.nio.file.Path path)
This constructor scans the path name of the
given path to detect prospective archive files using the
default archive detector.
On all platforms:
Path path = new TPath(Paths.get("app.war/WEB-INF/lib", "lib.jar/META-INF/MANIFEST.MF"));path - a path.private TPath(URI name, @CheckForNull TArchiveDetector detector, @CheckForNull FsPath address)
private static int prefixLength(String p)
private static FsPath address(URI name, TArchiveDetector detector)
private boolean invariants()
The constructors call this method like this:
assert invariants();
This calls the method if and only if assertions are enabled in order
to assert that the instance invariants are properly obeyed.
If assertions are disabled, the call to this method is thrown away by
the HotSpot compiler, so there is no performance penalty.
If assertions are enabled however, a call to this method will initialize all volatile fields as a side effect.
trueAssertionError - If assertions are enabled and any invariant is
violated.public static TArchiveDetector getDefaultArchiveDetector()
TConfig.get().getArchiveDetector().public static void setDefaultArchiveDetector(TArchiveDetector detector)
TConfig.get().setArchiveDetector(detector).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()URI getName()
URI.
Multiple invocations of this method will return the same object.URI.TArchiveDetector getArchiveDetector()
TArchiveDetector used for scanning this path's
name for prospective archive files at construction
time.
Multiple invocations of this method will return the same object.TArchiveDetector used for scanning this path's
name for prospective archive files at
construction time.private FsPath getAddress()
FsMountPoint getMountPoint()
FsEntryName getEntryName()
public TFileSystem getFileSystem()
TFileSystem for this path.
Multiple invocations of this method will return the same object.getFileSystem in interface java.nio.file.PathTFileSystem for this path.private TFileSystem getFileSystem0()
public boolean isAbsolute()
isAbsolute in interface java.nio.file.PathTPath getNonArchivePath()
@Nullable public TPath getRoot()
getRoot in interface java.nio.file.Path@Nullable public TPath getFileName()
getFileName in interface java.nio.file.Path@Nullable public TPath getParent()
getParent in interface java.nio.file.Pathprivate List<String> getElements()
name.
Multiple invocations of this method will return the same object.name.public int getNameCount()
getNameCount in interface java.nio.file.Pathpublic TPath getName(int index)
getName in interface java.nio.file.Pathpublic TPath subpath(int beginIndex, int endIndex)
subpath in interface java.nio.file.Pathpublic boolean startsWith(java.nio.file.Path that)
startsWith in interface java.nio.file.Pathpublic boolean startsWith(String other)
startsWith in interface java.nio.file.Pathpublic boolean endsWith(java.nio.file.Path that)
endsWith in interface java.nio.file.Pathpublic boolean endsWith(String other)
endsWith in interface java.nio.file.Pathpublic TPath normalize()
normalize in interface java.nio.file.Pathpublic TPath resolve(java.nio.file.Path other)
resolve in interface java.nio.file.Pathpublic TPath resolve(String other)
resolve in interface java.nio.file.Pathpublic TPath resolveSibling(java.nio.file.Path other)
resolveSibling in interface java.nio.file.Pathpublic TPath resolveSibling(String other)
resolveSibling in interface java.nio.file.Pathpublic TPath relativize(java.nio.file.Path other)
relativize in interface java.nio.file.Pathpublic URI toUri()
toUri in interface java.nio.file.Pathpublic TPath toAbsolutePath()
toAbsolutePath in interface java.nio.file.Pathpublic TPath toRealPath(java.nio.file.LinkOption... options) throws IOException
toRealPath in interface java.nio.file.PathIOExceptionpublic 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
this file object, even if it was a plain File object.toFile in interface java.nio.file.PathTFile object for this path.UnsupportedOperationException - if this path is not file based,
i.e. if the scheme component of the URI of
this path is not file.public java.nio.file.WatchKey register(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>[] events, java.nio.file.WatchEvent.Modifier... modifiers) throws IOException
register in interface java.nio.file.Pathregister in interface java.nio.file.WatchableUnsupportedOperationException - alwaysIOExceptionpublic java.nio.file.WatchKey register(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>... events) throws IOException
register in interface java.nio.file.Pathregister in interface java.nio.file.WatchableUnsupportedOperationException - alwaysIOExceptionpublic Iterator<java.nio.file.Path> iterator()
iterator in interface Iterable<java.nio.file.Path>iterator in interface java.nio.file.Pathpublic int compareTo(java.nio.file.Path that)
name.
On Windows, case is ignored when comparing the path names.compareTo in interface Comparable<java.nio.file.Path>compareTo in interface java.nio.file.Pathpublic boolean equals(Object that)
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.equals in interface java.nio.file.Pathequals in class Objectpublic int hashCode()
equals(Object).hashCode in interface java.nio.file.PathhashCode in class Objectequals(Object).public String toString()
toString in interface java.nio.file.PathtoString in class Objectprivate String toString0()
SeekableByteChannel newByteChannel(Set<? extends java.nio.file.OpenOption> options, java.nio.file.attribute.FileAttribute<?>... attrs) throws IOException
IOExceptionInputStream newInputStream(java.nio.file.OpenOption... options) throws IOException
IOExceptionOutputStream newOutputStream(java.nio.file.OpenOption... options) throws IOException
IOExceptionjava.nio.file.DirectoryStream<java.nio.file.Path> newDirectoryStream(java.nio.file.DirectoryStream.Filter<? super java.nio.file.Path> filter) throws IOException
IOExceptionvoid createDirectory(java.nio.file.attribute.FileAttribute<?>... attrs) throws IOException
IOExceptionvoid delete()
throws IOException
IOExceptionFsEntry getEntry() throws IOException
IOExceptionInputSocket<?> getInputSocket(BitField<FsInputOption> options)
OutputSocket<?> getOutputSocket(BitField<FsOutputOption> options, @CheckForNull Entry template)
void checkAccess(java.nio.file.AccessMode... modes) throws IOException
IOException@Nullable <V extends java.nio.file.attribute.FileAttributeView> V getFileAttributeView(Class<V> type, java.nio.file.LinkOption... options)
<A extends java.nio.file.attribute.BasicFileAttributes> A readAttributes(Class<A> type, java.nio.file.LinkOption... options) throws IOException
IOExceptionBitField<FsInputOption> mapInput(java.nio.file.OpenOption... options)
BitField<FsInputOption> mapInput(Set<? extends java.nio.file.OpenOption> options)
BitField<FsInputOption> getInputPreferences()
BitField<FsOutputOption> mapOutput(java.nio.file.OpenOption... options)
BitField<FsOutputOption> mapOutput(Set<? extends java.nio.file.OpenOption> options)
BitField<FsOutputOption> getOutputPreferences()
Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.