public class PathUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static Pattern |
GLOB_TOKENS |
| Constructor and Description |
|---|
PathUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Path |
addExtension(Path path,
String... extensions)
Suffix all
extensions to path. |
static Path |
combinePaths(String... paths) |
static boolean |
compareWithoutSchemeAndAuthority(Path path1,
Path path2)
Compare two path without shedme and authority (the prefix)
|
static Path |
deepestNonGlobPath(Path input)
Finds the deepest ancestor of input that is not a glob.
|
static void |
deleteEmptyParentDirectories(FileSystem fs,
Path limitPath,
Path startPath)
Deletes empty directories starting with startPath and all ancestors up to but not including limitPath.
|
static Path |
getPathWithoutSchemeAndAuthority(Path path)
Removes the Scheme and Authority from a Path.
|
static boolean |
isAbsoluteAndSchemeAuthorityNull(Path path)
Is an absolute path (ie a slash relative path part)
AND a scheme is null AND authority is null.
|
static boolean |
isAncestor(Path possibleAncestor,
Path fullPath)
Checks whether possibleAncestor is an ancestor of fullPath.
|
static boolean |
isGlob(Path path) |
static Path |
mergePaths(Path path1,
Path path2) |
static Path |
relativizePath(Path fullPath,
Path pathPrefix) |
static Path |
removeExtension(Path path,
String... extensions)
Removes all
extensions from path if they exist. |
static Path |
withoutLeadingSeparator(Path path)
Removes the leading slash if present.
|
public static final Pattern GLOB_TOKENS
public static boolean isAncestor(Path possibleAncestor, Path fullPath)
possibleAncestor - Possible ancestor of fullPath.fullPath - path to check.public static Path getPathWithoutSchemeAndAuthority(Path path)
public static Path withoutLeadingSeparator(Path path)
public static Path deepestNonGlobPath(Path input)
public static boolean isGlob(Path path)
public static Path removeExtension(Path path, String... extensions)
extensions from path if they exist.
PathUtils.removeExtention("file.txt", ".txt") = file
PathUtils.removeExtention("file.txt.gpg", ".txt", ".gpg") = file
PathUtils.removeExtention("file", ".txt") = file
PathUtils.removeExtention("file.txt", ".tar.gz") = file.txt
PathUtils.removeExtention("file.txt.gpg", ".txt") = file.gpg
PathUtils.removeExtention("file.txt.gpg", ".gpg") = file.txt
path - in which the extensions need to be removedextensions - to be removedPath without extensionspublic static Path addExtension(Path path, String... extensions)
extensions to path.
PathUtils.addExtension("/tmp/data/file", ".txt") = file.txt
PathUtils.addExtension("/tmp/data/file.txt.gpg", ".zip") = file.txt.gpg.zip
PathUtils.addExtension("/tmp/data/file.txt", ".tar", ".gz") = file.txt.tar.gz
PathUtils.addExtension("/tmp/data/file.txt.gpg", ".tar.txt") = file.txt.gpg.tar.txt
path - to which the extensions need to be addedextensions - to be addedPath with extensionspublic static boolean isAbsoluteAndSchemeAuthorityNull(Path path)
public static void deleteEmptyParentDirectories(FileSystem fs, Path limitPath, Path startPath) throws IOException
fs - FileSystem where paths are located.limitPath - only Paths that are strict descendants of this path will be deleted.startPath - first Path to delete. Afterwards empty ancestors will be deleted.IOException