-
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AzureFilePath
,FTPPath
,GcpFilePath
,HadoopFilePath
public interface Path extends Serializable
An abstract identifier for a resource. APath
represents 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 thefile
scheme 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
Path
if writing a new file system scheme, in which case it is necessary to also implement aFileSystemProvider
andFileSystem
as well.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
equals(Object o)
FileSystemProvider
getFileSystemProvider()
Gets the file system provider for this path.String
getName()
Gets the last element of the path.Path
getParent()
Gets the path referring to the location containing the path.int
hashCode()
boolean
isAbsolute()
Indicates whether the path is absolute or relative.Path
resolve(String childPath)
Adds additional elements to the path.Path
toAbsolutePath()
Converts a relative path into an absolute path.File
toFile()
Gets the local file corresponding to the path.String
toString()
Gets the string representation of the path.String
toURL()
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:
true
if the path starts from the file system root,false
otherwise.
-
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,
null
if 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
null
if 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
null
if 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())
.
-
-