Package org.apache.flink.core.fs
Class Path
- java.lang.Object
-
- org.apache.flink.core.fs.Path
-
- All Implemented Interfaces:
Serializable,IOReadableWritable
@Public public class Path extends Object implements IOReadableWritable, Serializable
Names a file or directory in aFileSystem. 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.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringCUR_DIRCharacter denoting the current directory.static StringSEPARATORThe directory separator, a slash.static charSEPARATOR_CHARThe directory separator, a slash (character).
-
Constructor Summary
Constructors Constructor Description Path()Constructs a new (empty) path object (used to reconstruct path object after RPC call).Path(String pathString)Construct a path from a String.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(String parent, Path child)Resolve a child path against a parent path.Path(URI uri)Constructs a path object from a given URI.Path(Path parent, String child)Resolve a child path against a parent path.Path(Path parent, Path child)Resolve a child path against a parent path.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Object o)intdepth()Returns the number of elements in this path.booleanequals(Object o)static PathfromLocalFile(File file)Creates a path for the given local file.FileSystemgetFileSystem()Returns the FileSystem that owns this Path.StringgetName()Returns the final component of this path, i.e., everything that follows the last separator.PathgetParent()Returns the parent of a path, i.e., everything that precedes the last separator ornullif at root.StringgetPath()Return full path.inthashCode()booleanhasWindowsDrive()Checks if the provided path string contains a windows drive letter.booleanisAbsolute()Checks if the directory of this path is absolute.PathmakeQualified(FileSystem fs)Returns a qualified path object.voidread(DataInputView in)Reads the object's internal data from the given data input view.Pathsuffix(String suffix)Adds a suffix to the final name in the path.StringtoString()URItoUri()Converts the path object to aURI.voidwrite(DataOutputView out)Writes the object's internal data to the given data output view.
-
-
-
Field Detail
-
SEPARATOR
public static final String SEPARATOR
The directory separator, a slash.- See Also:
- Constant Field Values
-
SEPARATOR_CHAR
public static final char SEPARATOR_CHAR
The directory separator, a slash (character).- See Also:
- Constant Field Values
-
CUR_DIR
public static final String CUR_DIR
Character denoting the current directory.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Path
public Path()
Constructs a new (empty) path object (used to reconstruct path object after RPC call).
-
Path
public Path(URI uri)
Constructs a path object from a given URI.- Parameters:
uri- the URI to construct the path object from
-
Path
public Path(String parent, String child)
Resolve a child path against a parent path.- Parameters:
parent- the parent pathchild- the child path
-
Path
public Path(Path parent, String child)
Resolve a child path against a parent path.- Parameters:
parent- the parent pathchild- the child path
-
Path
public Path(String parent, Path child)
Resolve a child path against a parent path.- Parameters:
parent- the parent pathchild- the child path
-
Path
public Path(Path parent, Path child)
Resolve a child path against a parent path.- Parameters:
parent- the parent pathchild- the child path
-
Path
public Path(String pathString)
Construct a path from a String. Path strings are URIs, but with unescaped elements and some additional normalization.- Parameters:
pathString- the string to construct a path from
-
-
Method Detail
-
toUri
public URI toUri()
Converts the path object to aURI.- Returns:
- the
URIobject converted from the path object
-
getFileSystem
public FileSystem getFileSystem() throws IOException
Returns the FileSystem that owns this Path.- Returns:
- the FileSystem that owns this Path
- Throws:
IOException- thrown if the file system could not be retrieved
-
isAbsolute
public boolean isAbsolute()
Checks if the directory of this path is absolute.- Returns:
trueif the directory of this path is absolute,falseotherwise
-
getName
public String getName()
Returns the final component of this path, i.e., everything that follows the last separator.- Returns:
- the final component of the path
-
getPath
public String getPath()
Return full path.- Returns:
- full path
-
getParent
public Path getParent()
Returns the parent of a path, i.e., everything that precedes the last separator ornullif at root.- Returns:
- the parent of a path or
nullif at root.
-
suffix
public Path suffix(String suffix)
Adds a suffix to the final name in the path.- Parameters:
suffix- The suffix to be added- Returns:
- the new path including the suffix
-
compareTo
public int compareTo(Object o)
-
depth
public int depth()
Returns the number of elements in this path.- Returns:
- the number of elements in this path
-
makeQualified
public Path makeQualified(FileSystem fs)
Returns a qualified path object.- Parameters:
fs- the FileSystem that should be used to obtain the current working directory- Returns:
- the qualified path object
-
read
public void read(DataInputView in) throws IOException
Description copied from interface:IOReadableWritableReads the object's internal data from the given data input view.- Specified by:
readin interfaceIOReadableWritable- Parameters:
in- the input view to read the data from- Throws:
IOException- thrown if any error occurs while reading from the input stream
-
write
public void write(DataOutputView out) throws IOException
Description copied from interface:IOReadableWritableWrites the object's internal data to the given data output view.- Specified by:
writein interfaceIOReadableWritable- Parameters:
out- the output view to receive the data.- Throws:
IOException- thrown if any error occurs while writing to the output stream
-
hasWindowsDrive
public boolean hasWindowsDrive()
Checks if the provided path string contains a windows drive letter.- Returns:
- True, if the path string contains a windows drive letter, false otherwise.
-
fromLocalFile
public static Path fromLocalFile(File file)
Creates a path for the given local 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.
- Parameters:
file- The file that the path should represent.- Returns:
- A path representing the local file URI of the given file.
-
-