@Public public class Path extends Object implements Serializable
FileSystem
. Path strings use slash as the directory
separator. A path string is absolute if it begins with a slash.
Tailing slashes are removed from the path.
Note: Path will no longer implement IOReadableWritable
in future versions. Please use
serializeToDataOutputView
and deserializeFromDataInputView
instead.
Modifier and Type | Field and Description |
---|---|
static String |
CUR_DIR
Character denoting the current directory.
|
static String |
SEPARATOR
The directory separator, a slash.
|
static char |
SEPARATOR_CHAR
The directory separator, a slash (character).
|
Constructor and Description |
---|
Path()
Constructs a new (empty) path object (used to reconstruct path object after RPC call).
|
Path(Path parent,
Path child)
Resolve a child path against a parent path.
|
Path(Path parent,
String child)
Resolve a child path against a parent path.
|
Path(String pathString)
Construct a path from a String.
|
Path(String parent,
Path child)
Resolve a child path against a parent path.
|
Path(String parent,
String child)
Resolve a child path against a parent path.
|
Path(String scheme,
String authority,
String path)
Construct a Path from a scheme, an authority and a path string.
|
Path(URI uri)
Constructs a path object from a given URI.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Object o) |
int |
depth()
Returns the number of elements in this path.
|
static Path |
deserializeFromDataInputView(DataInputView in)
Deserialize the Path from
DataInputView . |
boolean |
equals(Object o) |
static Path |
fromLocalFile(File file)
Creates a path for the given local file.
|
FileSystem |
getFileSystem()
Returns the FileSystem that owns this Path.
|
String |
getName()
Returns the final component of this path, i.e., everything that follows the last separator.
|
Path |
getParent()
Returns the parent of a path, i.e., everything that precedes the last separator or
null
if at root. |
String |
getPath()
Return full path.
|
int |
hashCode() |
boolean |
hasWindowsDrive()
Checks if the provided path string contains a windows drive letter.
|
boolean |
isAbsolute()
Checks if the directory of this path is absolute.
|
Path |
makeQualified(FileSystem fs)
Returns a qualified path object.
|
static void |
serializeToDataOutputView(Path path,
DataOutputView out)
Serialize the path to
DataInputView . |
Path |
suffix(String suffix)
Adds a suffix to the final name in the path.
|
String |
toString() |
URI |
toUri()
Converts the path object to a
URI . |
public static final String SEPARATOR
public static final char SEPARATOR_CHAR
public static final String CUR_DIR
public Path()
public Path(URI uri)
uri
- the URI to construct the path object frompublic Path(String parent, String child)
parent
- the parent pathchild
- the child pathpublic Path(Path parent, String child)
parent
- the parent pathchild
- the child pathpublic Path(String parent, Path child)
parent
- the parent pathchild
- the child pathpublic Path(Path parent, Path child)
parent
- the parent pathchild
- the child pathpublic Path(String pathString)
pathString
- the string to construct a path frompublic URI toUri()
URI
.URI
object converted from the path objectpublic FileSystem getFileSystem() throws IOException
IOException
- thrown if the file system could not be retrievedpublic boolean isAbsolute()
true
if the directory of this path is absolute, false
otherwisepublic String getName()
public String getPath()
public Path getParent()
null
if at root.null
if at root.public Path suffix(String suffix)
suffix
- The suffix to be addedpublic int compareTo(Object o)
public int depth()
public Path makeQualified(FileSystem fs)
fs
- the FileSystem that should be used to obtain the current working directorypublic boolean hasWindowsDrive()
public static Path fromLocalFile(File file)
This method is useful to make sure the path creation for local files works seamlessly across different operating systems. Especially Windows has slightly different rules for slashes between schema and a local file path, making it sometimes tricky to produce cross-platform URIs for local files.
file
- The file that the path should represent.@Nullable public static Path deserializeFromDataInputView(DataInputView in) throws IOException
DataInputView
.in
- the data input view.IOException
- if an error happened.public static void serializeToDataOutputView(Path path, DataOutputView out) throws IOException
DataInputView
.path
- the file path.out
- the data out put view.IOException
- if an error happened.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.