public final class PathUtils extends Object
TachyonURI 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
TachyonURI.SEPARATOR. |
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 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 String |
temporaryFileName(long fileId,
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... paths) throws IllegalArgumentException
TachyonURI.SEPARATOR.
For example,
concatPath("/myroot/", "dir", 1L, "filename").equals("/myroot/dir/1/filename");
concatPath("tachyon://myroot", "dir", "filename").equals("tachyon://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 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 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 prefixInvalidPathExceptionpublic 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 final String temporaryFileName(long fileId, long nonce, String path)
fileId - a file idnonce - a nonce tokenpath - a file pathpublic static final String uniqPath()
Copyright © 2015. All Rights Reserved.