Class FastPathResolver
java.lang.Object
nonapi.io.github.classgraph.utils.FastPathResolver
Resolve relative paths and URLs/URIs against a base path in a way that is faster than Java's URL/URI parser (and
much faster than Path), while aiming for cross-platform compatibility, and hopefully in particular being robust
to the many forms of Windows path weirdness.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
hexCharToInt
(char c) Hex char to int.static String
normalizePath
(String path, boolean isFileOrJarURL) Parse percent encoding, e.g.static String
Strip away any "jar:" prefix from a filename URI, and convert it to a file path, handling possibly-broken mixes of filesystem and URI conventions.static String
Strip away any "jar:" prefix from a filename URI, and convert it to a file path, handling possibly-broken mixes of filesystem and URI conventions; resolve relative paths relative to resolveBasePath.private static void
translateSeparator
(String path, int startIdx, int endIdx, boolean stripFinalSeparator, StringBuilder buf) Translate backslashes to forward slashes, optionally removing trailing separator.private static void
unescapePercentEncoding
(String path, int startIdx, int endIdx, StringBuilder buf) Unescape runs of percent encoding, e.g.
-
Field Details
-
percentMatcher
Match %-encoded characters in URLs. -
schemeTwoSlashMatcher
Match custom URLs that are followed by two slashes. -
schemeOneSlashMatcher
Match custom URLs that are followed by one slash.
-
-
Constructor Details
-
FastPathResolver
private FastPathResolver()Constructor.
-
-
Method Details
-
translateSeparator
private static void translateSeparator(String path, int startIdx, int endIdx, boolean stripFinalSeparator, StringBuilder buf) Translate backslashes to forward slashes, optionally removing trailing separator.- Parameters:
path
- the pathstartIdx
- the start indexendIdx
- the end indexstripFinalSeparator
- if true, strip the final separatorbuf
- the buf
-
hexCharToInt
private static int hexCharToInt(char c) Hex char to int.- Parameters:
c
- the character- Returns:
- the integer value of the character
-
unescapePercentEncoding
private static void unescapePercentEncoding(String path, int startIdx, int endIdx, StringBuilder buf) Unescape runs of percent encoding, e.g. "%20%43%20" -> " + "- Parameters:
path
- the pathstartIdx
- the start indexendIdx
- the end indexbuf
- the buf
-
normalizePath
Parse percent encoding, e.g. "%20" -> " "; convert '/' or '\\' to SEP; remove trailing separator char if present.- Parameters:
path
- The path to normalize.isFileOrJarURL
- True if this is a "file:" or "jar:" URL.- Returns:
- The normalized path.
-
resolve
Strip away any "jar:" prefix from a filename URI, and convert it to a file path, handling possibly-broken mixes of filesystem and URI conventions; resolve relative paths relative to resolveBasePath.- Parameters:
resolveBasePath
- The base path.relativePath
- The path to resolve relative to the base path.- Returns:
- The resolved path.
-
resolve
Strip away any "jar:" prefix from a filename URI, and convert it to a file path, handling possibly-broken mixes of filesystem and URI conventions. Returns null if relativePathStr is an "http(s):" path.- Parameters:
pathStr
- The path to resolve.- Returns:
- The resolved path.
-