public final class AzurePath extends Object implements Path
The root component, if it is present, is the first element of the path and is denoted by a ':'
as the last
character. Hence, only one instance of ':'
may appear in a path string and it may only be the last character
of the first element in the path. The root component is used to identify which container a path belongs to.
Constructing a syntactically valid path does not ensure a resource exists at the given path. An error will not be thrown until trying to access an invalid resource, e.g. trying to access a resource that does not exist.
Path names are case sensitive.
If a resource is accessed via a relative path, it will be resolved against the default directory of the file system.
The default directory is as defined in the AzureFileSystem
docs.
Leading and trailing separators will be stripped from each component passed to
AzureFileSystem.getPath(String, String...)
. This has the effect of treating "foo/" as though it were simply
"foo".
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Path path)
Compares two abstract paths lexicographically.
|
boolean |
endsWith(Path path)
Tests if this path ends with the given path.
|
boolean |
endsWith(String path)
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 o)
A path is considered equal to another path if it is associated with the same file system instance and if the
path strings are equivalent.
|
Path |
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.
|
Path |
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.
|
Path |
getParent()
Returns the parent path, or null if this path does not have a parent.
|
Path |
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() |
boolean |
isAbsolute()
Tells whether or not this path is absolute.
|
Iterator<Path> |
iterator()
Returns an iterator over the name elements of this path.
|
Path |
normalize()
Returns a path that is this path with redundant name elements eliminated.
|
WatchKey |
register(WatchService watchService,
WatchEvent.Kind<?>... kinds)
Unsupported.
|
WatchKey |
register(WatchService watchService,
WatchEvent.Kind<?>[] kinds,
WatchEvent.Modifier... modifiers)
Unsupported.
|
Path |
relativize(Path path)
Constructs a relative path between this path and a given path.
|
Path |
resolve(Path path)
Resolve the given path against this path.
|
Path |
resolve(String path)
Converts a given path string to a Path and resolves it against this Path in exactly the manner specified by the
resolve method. |
Path |
resolveSibling(Path path)
Resolves the given path against this path's parent path.
|
Path |
resolveSibling(String path)
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 path)
Tests if this path starts with the given path.
|
boolean |
startsWith(String path)
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.
|
Path |
subpath(int begin,
int end)
Returns a relative Path that is a subsequence of the name elements of this path.
|
Path |
toAbsolutePath()
Returns a Path object representing the absolute path of this path.
|
BlobClient |
toBlobClient()
Returns a
BlobClient which references a blob pointed to by this path. |
File |
toFile()
Unsupported.
|
Path |
toRealPath(LinkOption... linkOptions)
Unsupported.
|
String |
toString()
Returns the string representation of this path.
|
URI |
toUri()
Returns a URI to represent this path.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public FileSystem getFileSystem()
getFileSystem
in interface Path
public boolean isAbsolute()
An absolute path is complete in that it doesn't need to be combined with other path information in order to locate a file. A path is considered absolute in this file system if it contains a root component.
isAbsolute
in interface Path
public Path getRoot()
The root component of this path also identifies the Azure Storage Container in which the file is stored. This method will not validate that the root component corresponds to an actual file store/container in this file system. It will simply return the root component of the path if one is present and syntactically valid.
public Path getFileName()
getFileName
in interface Path
public Path getParent()
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 one or more elements, and no root component, then this method is equivalent to evaluating the
expression:
subpath(0, getNameCount()-1);
public int getNameCount()
getNameCount
in interface Path
public Path getName(int index)
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
.
getName
in interface Path
index
- the index of the elementIllegalArgumentException
- if index is negative, index is greater than or equal to the number of elements,
or this path has zero name elementspublic Path subpath(int begin, int end)
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(Path 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.
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.
In this implementation, a root component starts with another root component if the two root components are equivalent strings. In other words, if the files are stored in the same container.
startsWith
in interface Path
path
- the given pathpublic boolean startsWith(String path)
startsWith
in interface Path
path
- the given path stringInvalidPathException
- If the path string cannot be converted to a Path.public boolean endsWith(Path path)
If 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. 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.
In this implementation, a root component ends with another root component if the two root components are equivalent strings. In other words, if the files are stored in the same container.
public boolean endsWith(String path)
endsWith
in interface Path
path
- the given path stringInvalidPathException
- If the path string cannot be converted to a Path.public Path normalize()
It derives from this path, a path that does not contain redundant name elements. The "." and ".." are special names used to indicate the current directory and parent directory. 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 is it 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
public Path resolve(Path 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.
public Path resolve(String path)
resolve
method.resolve
in interface Path
path
- the path string to resolve against this pathInvalidPathException
- if the path string cannot be converted to a Path.public Path resolveSibling(Path path)
resolveSibling
in interface Path
path
- the path to resolve against this path's parentpublic Path resolveSibling(String path)
resolveSibling
in interface Path
path
- the path string to resolve against this path's parentInvalidPathException
- if the path string cannot be converted to a Path.public Path relativize(Path 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.
A relative path cannot be constructed if only one of the paths have a root component. If both paths have a root component, it is still possible to relativize one against the other. 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)
relativize
in interface Path
path
- the path to relativize against this pathIllegalArgumentException
- if other is not a Path that can be relativized against this pathpublic URI toUri()
This method constructs an absolute URI with a scheme equal to the URI scheme that identifies the provider.
No authority component is defined for the URI
returned by this method. This implementation offers the
same equivalence guarantee as the default provider.
toUri
in interface Path
SecurityException
- neverpublic Path toAbsolutePath()
If this path is already absolute then this method simply returns this path. Otherwise, this method resolves the path against the default directory.
toAbsolutePath
in interface Path
SecurityException
- neverpublic Path toRealPath(LinkOption... linkOptions) throws IOException
toRealPath
in interface Path
linkOptions
- optionsUnsupportedOperationException
- operation not suported.IOException
public File toFile()
toFile
in interface Path
UnsupportedOperationException
- operation not suported.public WatchKey register(WatchService watchService, WatchEvent.Kind<?>[] kinds, WatchEvent.Modifier... modifiers) throws IOException
register
in interface Path
register
in interface Watchable
watchService
- watchServicekinds
- kindsmodifiers
- modifiersUnsupportedOperationException
- operation not suported.IOException
public WatchKey register(WatchService watchService, WatchEvent.Kind<?>... kinds) throws IOException
register
in interface Path
register
in interface Watchable
watchService
- watchServicekinds
- kindsUnsupportedOperationException
- operation not suported.IOException
public Iterator<Path> iterator()
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 int compareTo(Path path)
This method may not be used to compare paths that are associated with different file system providers.
This result of this method is identical to a string comparison on the underlying path strings.
compareTo
in interface Comparable<Path>
compareTo
in interface Path
ClassCastException
- if the paths are associated with different providerspublic String toString()
If this path was created by converting a path string using the getPath method then the path string returned by this method may differ from the original String used to create the path.
The returned path string uses the default name separator to separate names in the path.
public boolean equals(Object o)
public int hashCode()
public BlobClient toBlobClient() throws IOException
BlobClient
which references a blob pointed to by this path. Note that this does not guarantee
the existence of the blob at this location.BlobClient
.IOException
- If the path only contains a root component or is emptyCopyright © 2021 Microsoft Corporation. All rights reserved.