@ThreadSafe public final class PathUtils extends Object
AlluxioURI
and local file paths.Modifier and Type | Method and Description |
---|---|
static String |
cleanPath(String path)
Checks and normalizes the given path.
|
static String |
concatPath(Object base,
Object... paths)
Joins each element in paths in order, separated by
AlluxioURI.SEPARATOR . |
static String |
concatPath(Object base,
Object path)
Joins two path elements, separated by
AlluxioURI.SEPARATOR . |
static AlluxioURI |
findLowestCommonAncestor(Collection<AlluxioURI> paths) |
static String |
getParent(String path)
Gets the parent of the file at a path.
|
static String[] |
getPathComponents(String path)
Gets the path components of the given path.
|
static String |
getPermanentFileName(String path) |
static boolean |
hasPrefix(String path,
String prefix)
Checks whether the given path contains the given prefix.
|
static boolean |
isRoot(String path)
Checks if the given path is the root.
|
static boolean |
isTemporaryFileName(String path)
Determines whether the given path is a temporary file name generated by Alluxio.
|
static String |
normalizePath(String path,
String separator)
Adds a trailing separator if it does not exist in path.
|
static String |
subtractPaths(String path,
String prefix)
Removes the prefix from the path, yielding a relative path from the second path to the first.
|
static String |
temporaryFileName(long nonce,
String path)
Generates a deterministic temporary file name for the a path and a file id and a nonce.
|
static String |
uniqPath()
Creates a unique path based off the caller.
|
static void |
validatePath(String path)
Checks if the given path is properly formed.
|
public static String cleanPath(String path) throws InvalidPathException
path
- The path to clean upInvalidPathException
- if the path is invalidpublic static String concatPath(Object base, Object path) throws IllegalArgumentException
AlluxioURI.SEPARATOR
.
Note that empty element in base or paths is ignored.
base
- base pathpath
- path element to concatenateIllegalArgumentException
- if base or paths is nullpublic static String concatPath(Object base, Object... paths) throws IllegalArgumentException
AlluxioURI.SEPARATOR
.
For example,
concatPath("/myroot/", "dir", 1L, "filename").equals("/myroot/dir/1/filename");
concatPath("alluxio://myroot", "dir", "filename").equals("alluxio://myroot/dir/filename");
concatPath("myroot/", "/dir/", "filename").equals("myroot/dir/filename");
concatPath("/", "dir", "filename").equals("/dir/filename");
Note that empty element in base or paths is ignored.base
- base pathpaths
- paths to concatenateIllegalArgumentException
- if base or paths is nullpublic static AlluxioURI findLowestCommonAncestor(Collection<AlluxioURI> paths)
paths
- the set of pathspublic static String getParent(String path) throws InvalidPathException
path
- The pathInvalidPathException
- if the path is invalidpublic static String[] getPathComponents(String path) throws InvalidPathException
path
- The path to splitInvalidPathException
- if the path is invalidpublic static String subtractPaths(String path, String prefix) throws InvalidPathException
path
- the full pathprefix
- the prefix to removeInvalidPathException
- if either of the arguments are not valid pathspublic static boolean hasPrefix(String path, String prefix) throws InvalidPathException
hasPrefix(/dir/file, /dir)
should evaluate to true, while
hasPrefix(/dir/file, /d)
should evaluate to false.path
- a pathprefix
- a prefixInvalidPathException
- when the path or prefix is invalidpublic static boolean isRoot(String path) throws InvalidPathException
path
- The path to checkInvalidPathException
- if the path is invalidpublic static void validatePath(String path) throws InvalidPathException
path
- The path to checkInvalidPathException
- If the path is not properly formedpublic static String temporaryFileName(long nonce, String path)
nonce
- a nonce tokenpath
- a file pathpublic static String getPermanentFileName(String path)
path
- the path of the file, possibly temporarypublic static boolean isTemporaryFileName(String path)
path
- the path to checkpublic static String uniqPath()
Copyright © 2023. All Rights Reserved.