public final class PathUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static com.google.common.base.CharMatcher |
NON_SLASH_MATCHER |
private static com.google.common.base.CharMatcher |
SLASH_MATCHER |
Modifier | Constructor and Description |
---|---|
private |
PathUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
collapseDots(java.lang.String path)
Removes all ../ and ./ entries from within the given path.
|
(package private) static boolean |
isAbsolute(java.lang.String path)
Determines if a path is absolute or not by testing for the presence of "/"
at the front of the string.
|
static java.lang.String |
makeAbsolute(java.lang.String path)
Converts the given path into an absolute one.
|
static java.lang.String |
makeAbsolute(java.lang.String path,
java.lang.String rootPath)
Converts the given path into an absolute one.
|
static java.lang.String |
makeRelative(java.lang.String basePath,
java.lang.String targetPath)
Returns targetPath relative to basePath.
|
(package private) static java.lang.String |
removeExtraneousSlashes(java.lang.String s)
Removes extra slashes from a path.
|
private static final com.google.common.base.CharMatcher SLASH_MATCHER
private static final com.google.common.base.CharMatcher NON_SLASH_MATCHER
public static java.lang.String collapseDots(java.lang.String path)
path
- The path to remove dots from.static boolean isAbsolute(java.lang.String path)
path
- The path to teststatic java.lang.String removeExtraneousSlashes(java.lang.String s)
public static java.lang.String makeAbsolute(java.lang.String path)
Unlike File.getAbsolutePath(), this function does remove .'s from the path and unlike File.getCanonicalPath(), this function does not resolve symlinks and does not use filesystem calls.
path
- The path to make absolute.public static java.lang.String makeAbsolute(java.lang.String path, java.lang.String rootPath)
Unlike File.getAbsolutePath(), this function does remove .'s from the path and unlike File.getCanonicalPath(), this function does not resolve symlinks and does not use filesystem calls.
rootPath
- The path to prefix to path if path is not already absolute.path
- The path to make absolute.public static java.lang.String makeRelative(java.lang.String basePath, java.lang.String targetPath)
basePath and targetPath must either both be relative, or both be absolute paths.
This function is different from makeRelative in that it is able to add in ../ components and collapse existing ones as well.
Examples: base="some/relative/path" target="some/relative/path/foo" return="foo" base="some/relative/path" target="some/relative" return=".." base="some/relative/path" target="foo/bar" return="../../../foo/bar" base="/some/abs/path" target="/foo/bar" return="../../../foo/bar"basePath
- The path to make targetPath relative to.targetPath
- The path to make relative.