Top Description Fields Constructors Methods
nonapi.io.github.classgraph.utils

public final Class FastPathResolver

extends Object
Class Inheritance
Imports
java.nio.charset.StandardCharsets, java.util.regex.Matcher, .Pattern, nonapi.io.github.classgraph.utils.VersionFinder.OperatingSystem

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

Modifier and TypeField and Description
private static final Pattern
percentMatcher

Match %-encoded characters in URLs.

private static final Pattern
schemeOneOrTwoSlashMatcher

Match custom URLs that are followed by one or two slashes.

Constructor Summary

AccessConstructor and Description
private
FastPathResolver()

Constructor.

Method Summary

Modifier and TypeMethod and Description
private static int

Returns:

the integer value of the character
hexCharToInt
(final char
the character
c
)

Hex char to int.

public static String

Returns:

The normalized path.
normalizePath
(final String
The path to normalize.
path
,
final boolean
True if this is a "file:" or "jar:" URL.
isFileOrJarURL
)

Parse percent encoding, e.g. "%20" -> " "; convert '/' or '\\' to SEP; remove trailing separator char if present.

public static String

Returns:

The resolved path.
resolve
(final String
The base path.
resolveBasePath
,
final String
The path to resolve relative to the base path.
relativePath
)

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.

public static String

Returns:

The resolved path.
resolve
(final String
The path to resolve.
pathStr
)

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.

private static void
translateSeparator(final String
the path
path
,
final int
the start index
startIdx
,
final int
the end index
endIdx
,
final boolean
if true, strip the final separator
stripFinalSeparator
,
final StringBuilder
the buf
buf
)

Translate backslashes to forward slashes, optionally removing trailing separator.

private static void
unescapePercentEncoding(final String
the path
path
,
final int
the start index
startIdx
,
final int
the end index
endIdx
,
final StringBuilder
the buf
buf
)

Unescape runs of percent encoding, e.g. "%20%43%20" -> " + "

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

percentMatcherback to summary
private static final Pattern percentMatcher

Match %-encoded characters in URLs.

schemeOneOrTwoSlashMatcherback to summary
private static final Pattern schemeOneOrTwoSlashMatcher

Match custom URLs that are followed by one or two slashes.

Constructor Detail

FastPathResolverback to summary
private FastPathResolver()

Constructor.

Method Detail

hexCharToIntback to summary
private static int hexCharToInt(final char c)

Hex char to int.

Parameters
c:char

the character

Returns:int

the integer value of the character

normalizePathback to summary
public static String normalizePath(final String path, final boolean isFileOrJarURL)

Parse percent encoding, e.g. "%20" -> " "; convert '/' or '\\' to SEP; remove trailing separator char if present.

Parameters
path:String

The path to normalize.

isFileOrJarURL:boolean

True if this is a "file:" or "jar:" URL.

Returns:String

The normalized path.

resolveback to summary
public static String resolve(final String resolveBasePath, final String relativePath)

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:String

The base path.

relativePath:String

The path to resolve relative to the base path.

Returns:String

The resolved path.

resolveback to summary
public static String resolve(final String pathStr)

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:String

The path to resolve.

Returns:String

The resolved path.

translateSeparatorback to summary
private static void translateSeparator(final String path, final int startIdx, final int endIdx, final boolean stripFinalSeparator, final StringBuilder buf)

Translate backslashes to forward slashes, optionally removing trailing separator.

Parameters
path:String

the path

startIdx:int

the start index

endIdx:int

the end index

stripFinalSeparator:boolean

if true, strip the final separator

buf:StringBuilder

the buf

unescapePercentEncodingback to summary
private static void unescapePercentEncoding(final String path, final int startIdx, final int endIdx, final StringBuilder buf)

Unescape runs of percent encoding, e.g. "%20%43%20" -> " + "

Parameters
path:String

the path

startIdx:int

the start index

endIdx:int

the end index

buf:StringBuilder

the buf