| Constructor and Description |
|---|
DesugarUnixPath(FileSystem fileSystem,
String rawPath,
String userDir,
String rootDir) |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Path other)
Compares two abstract paths lexicographically.
|
boolean |
endsWith(Path other)
Tests if this path ends with the given path.
|
boolean |
endsWith(String other)
Tests if this path ends with a
Path, constructed by converting
the given path string, in exactly the manner specified by the endsWith(Path) method. |
boolean |
equals(Object other)
Compares this instance with the specified object and indicates if they
are equal.
|
DesugarUnixPath |
getFileName()
Returns the name of the file or directory denoted by this path as a
Path object. |
FileSystem |
getFileSystem()
Returns the file system that created this object.
|
DesugarUnixPath |
getName(int index)
Returns a name element of this path as a
Path object. |
int |
getNameCount()
Returns the number of name elements in the path.
|
DesugarUnixPath |
getParent()
Returns the parent path, or
null if this path does not
have a parent. |
DesugarUnixPath |
getRoot()
Returns the root component of this path as a
Path object,
or null if this path does not have a root component. |
int |
hashCode()
Returns an integer hash code for this object.
|
boolean |
isAbsolute()
Tells whether or not this path is absolute.
|
Iterator<Path> |
iterator()
Returns an iterator over the name elements of this path.
|
DesugarUnixPath |
normalize()
Returns a path that is this path with redundant name elements eliminated.
|
WatchKey |
register(WatchService watcher,
WatchEvent.Kind<?>[] events,
WatchEvent.Modifier... modifiers)
Registers the file located by this path with a watch service.
|
DesugarUnixPath |
relativize(Path other)
Constructs a relative path between this path and a given path.
|
DesugarUnixPath |
resolve(Path other)
Resolve the given path against this path.
|
DesugarUnixPath |
resolveSibling(Path other)
Resolves the given path against this path's
parent
path. |
DesugarUnixPath |
resolveSibling(String other)
Converts a given path string to a
Path and resolves it against
this path's parent path in exactly the manner
specified by the resolveSibling method. |
boolean |
startsWith(Path other)
Tests if this path starts with the given path.
|
boolean |
startsWith(String other)
Tests if this path starts with a
Path, constructed by converting
the given path string, in exactly the manner specified by the startsWith(Path) method. |
DesugarUnixPath |
subpath(int beginIndex,
int endIndex)
Returns a relative
Path that is a subsequence of the name
elements of this path. |
DesugarUnixPath |
toAbsolutePath()
Returns a
Path object representing the absolute path of this
path. |
File |
toFile()
Returns a
File object representing this path. |
DesugarUnixPath |
toRealPath(LinkOption... options)
Returns the real path of an existing file.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
URI |
toUri()
Returns a URI to represent this path.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic DesugarUnixPath(FileSystem fileSystem, String rawPath, String userDir, String rootDir)
public FileSystem getFileSystem()
PathgetFileSystem in interface Pathpublic boolean isAbsolute()
PathAn absolute path is complete in that it doesn't need to be combined with other path information in order to locate a file.
isAbsolute in interface Pathtrue if, and only if, this path is absolutepublic DesugarUnixPath getRoot()
PathPath object,
or null if this path does not have a root component.public DesugarUnixPath getFileName()
PathPath object. The file name is the farthest element from
the root in the directory hierarchy.getFileName in interface Pathnull if this path has zero elementspublic DesugarUnixPath getParent()
Pathnull if this path does not
have a parent.
The parent of this path object consists of this path's root
component, if any, and each element in the path except for the
farthest from the root in the directory hierarchy. This method
does not access the file system; the path or its parent may not exist.
Furthermore, this method does not eliminate special names such as "."
and ".." that may be used in some implementations. On UNIX for example,
the parent of "/a/b/c" is "/a/b", and the parent of
"x/y/." is "x/y". This method may be used with the normalize method, to eliminate redundant names, for cases where
shell-like navigation is required.
If this path has more than one element, and no root component, then this method is equivalent to evaluating the expression:
subpath(0, getNameCount()-1);
public int getNameCount()
PathgetNameCount in interface Path0 if this path
only represents a root componentpublic DesugarUnixPath getName(int index)
PathPath object.
The index parameter is the index of the name element to return.
The element that is closest to the root in the directory hierarchy
has index 0. The element that is farthest from the root
has index count-1.
public DesugarUnixPath subpath(int beginIndex, int endIndex)
PathPath that is a subsequence of the name
elements of this path.
The beginIndex and endIndex parameters specify the
subsequence of name elements. The name that is closest to the root
in the directory hierarchy has index 0. The name that is
farthest from the root has index count-1. The returned Path object has the name elements
that begin at beginIndex and extend to the element at index endIndex-1.
public boolean startsWith(String other)
PathPath, constructed by converting
the given path string, in exactly the manner specified by the startsWith(Path) method. On UNIX for example, the path
"foo/bar" starts with "foo" and "foo/bar". It
does not start with "f" or "fo".startsWith in interface Pathother - the given path stringtrue if this path starts with the given path; otherwise
falsepublic boolean startsWith(Path other)
Path This path starts with the given path if this path's root
component starts with the root component of the given path,
and this path starts with the same name elements as the given path.
If the given path has more name elements than this path then false
is returned.
Whether or not the root component of this path starts with the root component of the given path is file system specific. If this path does not have a root component and the given path has a root component then this path does not start with the given path.
If the given path is associated with a different FileSystem
to this path then false is returned.
startsWith in interface Pathother - the given pathtrue if this path starts with the given path; otherwise
falsepublic boolean endsWith(String other)
PathPath, constructed by converting
the given path string, in exactly the manner specified by the endsWith(Path) method. On UNIX for example, the path
"foo/bar" ends with "foo/bar" and "bar". It does
not end with "r" or "/bar". Note that trailing separators
are not taken into account, and so invoking this method on the Path"foo/bar" with the String "bar/" returns
true.public boolean endsWith(Path other)
PathIf the given path has N elements, and no root component, and this path has N or more elements, then this path ends with the given path if the last N elements of each path, starting at the element farthest from the root, are equal.
If the given path has a root component then this path ends with the given path if the root component of this path ends with the root component of the given path, and the corresponding elements of both paths are equal. Whether or not the root component of this path ends with the root component of the given path is file system specific. If this path does not have a root component and the given path has a root component then this path does not end with the given path.
If the given path is associated with a different FileSystem
to this path then false is returned.
public boolean equals(Object other)
Objecto must represent the same object
as this instance using a class-specific comparison. The general contract
is that this comparison should be reflexive, symmetric, and transitive.
Also, no object reference other than null is equal to null.
The default implementation returns true only if this ==
o. See Writing a correct
equals method
if you intend implementing your own equals method.
The general contract for the equals and Object.hashCode() methods is that if equals returns true for
any two objects, then hashCode() must return the same value for
these objects. This means that subclasses of Object usually
override either both methods or neither of them.
equals in interface Pathequals in class Objectother - the object to compare this instance with.true if the specified object is equal to this Object; false otherwise.Object.hashCode()public int hashCode()
ObjectObject.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
hashCode in interface PathhashCode in class ObjectObject.equals(java.lang.Object)public int compareTo(Path other)
PathThis method may not be used to compare paths that are associated with different file system providers.
compareTo in interface Comparable<Path>compareTo in interface Pathother - the path compared to this path.equal to this path, a
value less than zero if this path is lexicographically less than
the argument, or a value greater than zero if this path is
lexicographically greater than the argumentpublic DesugarUnixPath normalize()
Path The precise definition of this method is implementation dependent but
in general it derives from this path, a path that does not contain
redundant name elements. In many file systems, the "."
and ".." are special names used to indicate the current directory
and parent directory. In such file systems all occurrences of "."
are considered redundant. If a ".." is preceded by a
non-".." name then both names are considered redundant (the
process to identify such names is repeated until it is no longer
applicable).
This method does not access the file system; the path may not locate
a file that exists. Eliminating ".." and a preceding name from a
path may result in the path that locates a different file than the original
path. This can arise when the preceding name is a symbolic link.
normalize in interface PathPath.getParent(),
Path.toRealPath(java.nio.file.LinkOption...)public DesugarUnixPath resolve(Path other)
Path If the other parameter is an absolute
path then this method trivially returns other. If other
is an empty path then this method trivially returns this path.
Otherwise this method considers this path to be a directory and resolves
the given path against this path. In the simplest case, the given path
does not have a root component, in which case this method
joins the given path to this path and returns a resulting path
that ends with the given path. Where the given path has
a root component then resolution is highly implementation dependent and
therefore unspecified.
resolve in interface Pathother - the path to resolve against this pathPath.relativize(java.nio.file.Path)public DesugarUnixPath resolveSibling(Path other)
Pathparent
path. This is useful where a file name needs to be replaced with
another file name. For example, suppose that the name separator is
"/" and a path represents "dir1/dir2/foo", then invoking
this method with the Path "bar" will result in the Path "dir1/dir2/bar". If this path does not have a parent path,
or other is absolute, then this method
returns other. If other is an empty path then this method
returns this path's parent, or where this path doesn't have a parent, the
empty path.resolveSibling in interface Pathother - the path to resolve against this path's parentPath.resolve(Path)public DesugarUnixPath resolveSibling(String other)
PathPath and resolves it against
this path's parent path in exactly the manner
specified by the resolveSibling method.resolveSibling in interface Pathother - the path string to resolve against this path's parentFileSystem.getPath(java.lang.String, java.lang.String...)public DesugarUnixPath relativize(Path other)
Path Relativization is the inverse of resolution.
This method attempts to construct a relative path
that when resolved against this path, yields a
path that locates the same file as the given path. For example, on UNIX,
if this path is "/a/b" and the given path is "/a/b/c/d"
then the resulting relative path would be "c/d". Where this
path and the given path do not have a root component,
then a relative path can be constructed. A relative path cannot be
constructed if only one of the paths have a root component. Where both
paths have a root component then it is implementation dependent if a
relative path can be constructed. If this path and the given path are
equal then an empty path is returned.
For any two normalized paths p and
q, where q does not have a root component,
p.relativize(p.resolve(q)).equals(q)
When symbolic links are supported, then whether the resulting path,
when resolved against this path, yields a path that can be used to locate
the same file as other is implementation
dependent. For example, if this path is "/a/b" and the given
path is "/a/x" then the resulting relative path may be "../x". If "b" is a symbolic link then is implementation
dependent if "a/b/../x" would locate the same file as "/a/x".
relativize in interface Pathother - the path to relativize against this pathpublic File toFile()
PathFile object representing this path. Where this Path is associated with the default provider, then this method is
equivalent to returning a File object constructed with the
String representation of this path.
If this path was created by invoking the File toPath method then there is no guarantee that the File object returned by this method is equal to the
original File.
public URI toUri()
Path This method constructs an absolute URI with a scheme equal to the URI scheme that identifies the
provider. The exact form of the scheme specific part is highly provider
dependent.
In the case of the default provider, the URI is hierarchical with
a path component that is absolute. The query and
fragment components are undefined. Whether the authority component is
defined or not is implementation dependent. There is no guarantee that
the URI may be used to construct a java.io.File.
In particular, if this path represents a Universal Naming Convention (UNC)
path, then the UNC server name may be encoded in the authority component
of the resulting URI. In the case of the default provider, and the file
exists, and it can be determined that the file is a directory, then the
resulting URI will end with a slash.
The default provider provides a similar round-trip guarantee
to the File class. For a given Path p it
is guaranteed that
so long as the originalPath.of(p.toUri()).equals(p.toAbsolutePath())
Path, the URI, and the new Path are all created in (possibly different invocations of) the same
Java virtual machine. Whether other providers make any guarantees is
provider specific and therefore unspecified.
When a file system is constructed to access the contents of a file as a file system then it is highly implementation specific if the returned URI represents the given path in the file system or it represents a compound URI that encodes the URI of the enclosing file system. A format for compound URIs is not defined in this release; such a scheme may be added in a future release.
public DesugarUnixPath toAbsolutePath()
PathPath object representing the absolute path of this
path.
If this path is already absolute then this
method simply returns this path. Otherwise, this method resolves the path
in an implementation dependent manner, typically by resolving the path
against a file system default directory. Depending on the implementation,
this method may throw an I/O error if the file system is not accessible.
toAbsolutePath in interface PathPath object representing the absolute pathpublic DesugarUnixPath toRealPath(LinkOption... options) throws IOException
Path The precise definition of this method is implementation dependent but
in general it derives from this path, an absolute
path that locates the same file as this path, but
with name elements that represent the actual name of the directories
and the file. For example, where filename comparisons on a file system
are case insensitive then the name elements represent the names in their
actual case. Additionally, the resulting path has redundant name
elements removed.
If this path is relative then its absolute path is first obtained,
as if by invoking the toAbsolutePath method.
The options array may be used to indicate how symbolic links
are handled. By default, symbolic links are resolved to their final
target. If the option NOFOLLOW_LINKS is
present then this method does not resolve symbolic links.
Some implementations allow special names such as ".." to refer to
the parent directory. When deriving the real path, and a
".." (or equivalent) is preceded by a non-".." name then
an implementation will typically cause both names to be removed. When
not resolving symbolic links and the preceding name is a symbolic link
then the names are only removed if it guaranteed that the resulting path
will locate the same file as this path.
toRealPath in interface Pathoptions - options indicating how symbolic links are handledIOException - if the file does not exist or an I/O error occurspublic String toString()
ObjectgetClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString method
if you intend implementing your own toString method.
public Iterator<Path> iterator()
Path The first element returned by the iterator represents the name
element that is closest to the root in the directory hierarchy, the
second element is the next closest, and so on. The last element returned
is the name of the file or directory denoted by this path. The root component, if present, is not returned by the iterator.
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException
Path In this release, this path locates a directory that exists. The
directory is registered with the watch service so that entries in the
directory can be watched. The events parameter is the events to
register and may contain the following events:
ENTRY_CREATE -
entry created or moved into the directoryENTRY_DELETE -
entry deleted or moved out of the directoryENTRY_MODIFY -
entry in directory was modified The context for these events is the
relative path between the directory located by this path, and the path
that locates the directory entry that is created, deleted, or modified.
The set of events may include additional implementation specific
event that are not defined by the enum StandardWatchEventKinds
The modifiers parameter specifies modifiers that
qualify how the directory is registered. This release does not define any
standard modifiers. It may contain implementation specific
modifiers.
Where a file is registered with a watch service by means of a symbolic link then it is implementation specific if the watch continues to depend on the existence of the symbolic link after it is registered.
register in interface Pathregister in interface Watchablewatcher - the watch service to which this object is to be registeredevents - the events for which this object should be registeredmodifiers - the modifiers, if any, that modify how the object is registeredNotDirectoryException - if the file is registered to watch the entries in a directory
and the file is not a directory (optional specific exception)IOException - if an I/O error occurs