@Immutable @DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class) public final class TPath extends Object implements 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(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(AccessMode... modes) |
int |
compareTo(Path that)
The natural ordering imposed by this implementation is identical to the
natural ordering of path's
name. |
(package private) void |
createDirectory(FileAttribute<?>... attrs) |
private static String |
cutLeadingSeparators(String p) |
(package private) static String |
cutTrailingSeparators(String p,
int o) |
(package private) void |
delete() |
boolean |
endsWith(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 FileAttributeView> |
getFileAttributeView(Class<V> type,
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<Path> |
iterator() |
(package private) BitField<FsInputOption> |
mapInput(OpenOption... options) |
(package private) BitField<FsInputOption> |
mapInput(Set<? extends OpenOption> options) |
(package private) BitField<FsOutputOption> |
mapOutput(OpenOption... options) |
(package private) BitField<FsOutputOption> |
mapOutput(Set<? extends OpenOption> options) |
private static URI |
name(String first,
String... more) |
private static URI |
name(URI uri) |
(package private) SeekableByteChannel |
newByteChannel(Set<? extends OpenOption> options,
FileAttribute<?>... attrs) |
(package private) DirectoryStream<Path> |
newDirectoryStream(DirectoryStream.Filter<? super Path> filter) |
(package private) InputStream |
newInputStream(OpenOption... options) |
(package private) OutputStream |
newOutputStream(OpenOption... options) |
TPath |
normalize() |
private static int |
prefixLength(String p) |
(package private) <A extends BasicFileAttributes> |
readAttributes(Class<A> type,
LinkOption... options) |
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) |
private TPath |
resolve(URI m) |
TPath |
resolveSibling(Path other) |
TPath |
resolveSibling(String other) |
static void |
setDefaultArchiveDetector(TArchiveDetector detector)
Equivalent to
TConfig.get().setArchiveDetector(detector). |
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 |
toRealPath(LinkOption... options) |
String |
toString() |
private String |
toString0() |
URI |
toUri() |
private final FsPath address
private static final TPath.TPathComparator COMPARATOR
private final TArchiveDetector detector
@CheckForNull private volatile List<String> elements
@CheckForNull private volatile TFileSystem fileSystem
@CheckForNull private volatile Integer hashCode
private final URI name
@CheckForNull private volatile String string
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(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.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.private TPath(URI name, @CheckForNull TArchiveDetector detector, @CheckForNull FsPath address)
private static FsPath address(URI name, TArchiveDetector detector)
void checkAccess(AccessMode... modes) throws IOException
IOExceptionpublic int compareTo(Path that)
name.
On Windows, case is ignored when comparing the path names.compareTo in interface Comparable<Path>compareTo in interface Pathvoid createDirectory(FileAttribute<?>... attrs) throws IOException
IOExceptionvoid delete()
throws IOException
IOExceptionpublic 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.private FsPath getAddress()
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.public static TArchiveDetector getDefaultArchiveDetector()
TConfig.get().getArchiveDetector().private List<String> getElements()
name.
Multiple invocations of this method will return the same object.name.FsEntry getEntry() throws IOException
IOExceptionFsEntryName getEntryName()
@Nullable <V extends FileAttributeView> V getFileAttributeView(Class<V> type, LinkOption... options)
@Nullable public TPath getFileName()
getFileName in interface Pathpublic TFileSystem getFileSystem()
TFileSystem for this path.
Multiple invocations of this method will return the same object.getFileSystem in interface PathTFileSystem for this path.private TFileSystem getFileSystem0()
BitField<FsInputOption> getInputPreferences()
InputSocket<?> getInputSocket(BitField<FsInputOption> options)
FsMountPoint getMountPoint()
URI getName()
URI.
Multiple invocations of this method will return the same object.URI.public int getNameCount()
getNameCount in interface PathTPath getNonArchivePath()
BitField<FsOutputOption> getOutputPreferences()
OutputSocket<?> getOutputSocket(BitField<FsOutputOption> options, @CheckForNull Entry template)
public int hashCode()
equals(Object).hashCode in interface PathhashCode in class Objectequals(Object).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 boolean isAbsolute()
isAbsolute in interface Pathpublic 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()BitField<FsInputOption> mapInput(OpenOption... options)
BitField<FsInputOption> mapInput(Set<? extends OpenOption> options)
BitField<FsOutputOption> mapOutput(OpenOption... options)
BitField<FsOutputOption> mapOutput(Set<? extends OpenOption> options)
SeekableByteChannel newByteChannel(Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
IOExceptionDirectoryStream<Path> newDirectoryStream(DirectoryStream.Filter<? super Path> filter) throws IOException
IOExceptionInputStream newInputStream(OpenOption... options) throws IOException
IOExceptionOutputStream newOutputStream(OpenOption... options) throws IOException
IOExceptionprivate static int prefixLength(String p)
<A extends BasicFileAttributes> A readAttributes(Class<A> type, LinkOption... options) throws IOException
IOExceptionpublic WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws IOException
register in interface Pathregister in interface WatchableUnsupportedOperationException - alwaysIOExceptionpublic WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException
register in interface Pathregister in interface WatchableUnsupportedOperationException - alwaysIOExceptionpublic TPath relativize(Path other)
relativize in interface Pathpublic TPath resolveSibling(Path other)
resolveSibling in interface Pathpublic TPath resolveSibling(String other)
resolveSibling in interface Pathpublic static void setDefaultArchiveDetector(TArchiveDetector detector)
TConfig.get().setArchiveDetector(detector).public boolean startsWith(Path that)
startsWith in interface Pathpublic boolean startsWith(String other)
startsWith in interface Pathpublic TPath toAbsolutePath()
toAbsolutePath in interface Pathpublic 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.toFile in interface 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 TPath toRealPath(LinkOption... options) throws IOException
toRealPath in interface PathIOExceptionpublic String toString()
private String toString0()
Copyright © 2004-2011 Schlichtherle IT Services. All Rights Reserved.