-
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AzureFilePath,FTPPath,GcpFilePath,HadoopFilePath
public interface Path extends Serializable
An abstract identifier for a resource. APathrepresents a location in aFileSystem. Paths are normally constructed via the methods available inPaths.Paths present a hierarchical structure for locating resources, identifying a resource based on a sequential traversal of elements, typically starting from some root. The methods of this interface deal only with the structural aspects of paths, not with the data which they identified. To actually access the data represented by a path, use the methods found in
FileClient.Paths are identified using a URI-like syntax, using a scheme prefix of
: to identify the type of file system. The remainder identifies the specific instance of the file system and the path to the element. The local file system is a special exception. While thefilescheme is recognized, a scheme is not required; path strings with no scheme are assumed to be local files. Some examples of path strings are:file:/home/myuser/myfile C:\temp\myfile ../siblingfile hdfs://namenode:9000/path/to/file
It is only necessary to implement a
Pathif writing a new file system scheme, in which case it is necessary to also implement aFileSystemProviderandFileSystemas well.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanequals(Object o)FileSystemProvidergetFileSystemProvider()Gets the file system provider for this path.StringgetName()Gets the last element of the path.PathgetParent()Gets the path referring to the location containing the path.inthashCode()booleanisAbsolute()Indicates whether the path is absolute or relative.Pathresolve(String childPath)Adds additional elements to the path.PathtoAbsolutePath()Converts a relative path into an absolute path.FiletoFile()Gets the local file corresponding to the path.StringtoString()Gets the string representation of the path.StringtoURL()Returns the URL string corresponding to this path.
-
-
-
Method Detail
-
getFileSystemProvider
FileSystemProvider getFileSystemProvider()
Gets the file system provider for this path.- Returns:
- the file system provider associated with the path
-
isAbsolute
boolean isAbsolute()
Indicates whether the path is absolute or relative. That is, does the path start from the root of the associated file system.For most file systems, all paths are absolute.
- Returns:
trueif the path starts from the file system root,falseotherwise.
-
toAbsolutePath
Path toAbsolutePath()
Converts a relative path into an absolute path.- Returns:
- the absolute path pointing to the same location. If the path is already absolute, it is returned.
-
getParent
Path getParent()
Gets the path referring to the location containing the path.- Returns:
- the path to the container of this path,
nullif this path is the root.
-
getName
String getName()
Gets the last element of the path.- Returns:
- the last element of the path.
-
resolve
Path resolve(String childPath)
Adds additional elements to the path. The provided string is interpreted as a relative path starting from the path's location.- Parameters:
childPath- the- Returns:
- the resulting path
-
toFile
File toFile()
Gets the local file corresponding to the path. This only makes sense when the path refers to the local file system. For other paths, it always returnsnull.- Returns:
- the file which this path identifies
or
nullif it does not identify a file on the local file system.
-
toURL
String toURL()
Returns the URL string corresponding to this path.- Returns:
- The URL string for this path, or
nullif this path cannot be mapped to a URL.
-
toString
String toString()
Gets the string representation of the path. It must be true thatPaths.asPath(path.toString())refers to the same location aspath. However, it may not the case thatpathString.equals(Paths.asPath(pathString).toString()).
-
-