@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 String |
concatUfsPath(String base,
String path)
Join two path elements for ufs, separated by
AlluxioURI.SEPARATOR . |
static AlluxioURI |
findLowestCommonAncestor(Collection<AlluxioURI> paths) |
static String[] |
getCleanedPathComponents(String path)
Get the components of a path that has already been cleaned.
|
static String |
getFirstLevelDirectory(String path)
Gets the first level directory of the path.
|
static String |
getParent(String path)
Gets the parent of the file at a path.
|
static String |
getParentCleaned(String cleanedPath)
The same as
getParent(java.lang.String) except does not clean the path before getting the parent. |
static String[] |
getPathComponents(String path)
Gets the path components of the given path.
|
static String |
getPermanentFileName(String path) |
static String |
getPersistentTmpPath(AlluxioConfiguration ufsConfiguration,
String path)
Get temp path for async persistence job.
|
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)
AlluxioURI.SEPARATOR
.
Note that empty element in base or paths is ignored.
base
- base pathpath
- path element to concatenatepublic 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 getParentCleaned(String cleanedPath) throws InvalidPathException
getParent(java.lang.String)
except does not clean the path before getting the parent.cleanedPath
- the path that has been cleanedInvalidPathException
- if the path is invalidpublic static String getFirstLevelDirectory(String path) throws InvalidPathException
getFirstLevelDirectory("/a/xx/").equals("/a");
getFirstLevelDirectory("/a/").equals("/a");
path
- the pathInvalidPathException
- if the path is the root or invalidpublic static String concatUfsPath(String base, String path)
AlluxioURI.SEPARATOR
.
For example,
concatUfsPath("s3://myroot/", "filename").equals("s3://myroot/filename");
concatUfsPath("s3://", "filename").equals("s3://filename");
base
- base pathpath
- path element to concatenatepublic static String getPersistentTmpPath(AlluxioConfiguration ufsConfiguration, String path)
ufsConfiguration
- the ufs configurationpath
- ufs pathpublic static String[] getPathComponents(String path) throws InvalidPathException
path
- The path to splitInvalidPathException
- if the path is invalidpublic static String[] getCleanedPathComponents(String path) throws InvalidPathException
path
- the pathInvalidPathException
public 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.