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

public final Class JarUtils

extends Object
Class Inheritance
Imports
java.io.File, java.util.ArrayList, .HashSet, .List, .Set, java.util.regex.Matcher, .Pattern, nonapi.io.github.classgraph.fastzipfilereader.NestedJarHandler, nonapi.io.github.classgraph.scanspec.ScanSpec

Jarfile utilities.

Field Summary

Modifier and TypeField and Description
private static final Pattern
DASH_VERSION

The Constant DASH_VERSION.

private static final Pattern
LEADING_DOTS

The Constant LEADING_DOTS.

private static final Pattern
NON_ALPHANUM

The Constant NON_ALPHANUM.

private static final Pattern
REPEATING_DOTS

The Constant REPEATING_DOTS.

private static final Pattern
TRAILING_DOTS

The Constant TRAILING_DOTS.

private static final int[]
UNIX_NON_PATH_SEPARATOR_COLON_POSITIONS

The position of the colon characters in the corresponding UNIX_NON_PATH_SEPARATORS array entry.

private static final String[]
UNIX_NON_PATH_SEPARATORS

On everything but Windows, where the path separator is ':', need to treat the colon in these substrings as non-separators, when at the beginning of the string or following a ':'.

public static final Pattern
URL_SCHEME_PATTERN

Check if a path has a URL scheme at the beginning.

Constructor Summary

AccessConstructor and Description
private
JarUtils()

Constructor.

Method Summary

Modifier and TypeMethod and Description
private static void
appendPathElt(final Object
the path element
pathElt
,
final StringBuilder
the buf
buf
)

Append a path element to a buffer.

public static String

Returns:

the class name
classfilePathToClassName
(final String
the classfile path
classfilePath
)

Convert a classfile path to the corresponding class name.

public static String

Returns:

the classfile path
classNameToClassfilePath
(final String
the class name
className
)

Convert a class name to the corresponding classfile path.

public static String

Returns:

The automatic module name.
derivedAutomaticModuleName
(final String
The jar path.
jarPath
)

Derive automatic module name from jar name, using this algorithm.

public static String

Returns:

The leafname of the path.
leafName
(final String
A file path.
path
)

Returns the leafname of a path, after first stripping off everything after the first '!', if present.

public static String

Returns:

The delimited path formed out of the path elements.
pathElementsToPathStr
(final Object...
The path elements.
pathElts
)

Get a set of path elements as a string, from an array of objects (e.g. of String, File or URL type, whose toString() method will be called to get the path component), and return the path as a single string delineated with the standard path separator character.

public static String

Returns:

The delimited path formed out of the path elements, after calling each of their toString() methods.
pathElementsToPathStr
(final Iterable<?>
The path elements.
pathElts
)

Get a set of path elements as a string, from an array of objects (e.g. of String, File or URL type, whose toString() method will be called to get the path component), and return the path as a single string delineated with the standard path separator character.

public static String[]

Returns:

The path element substrings.
smartPathSplit
(final String
The path to split.
pathStr
,
final ScanSpec
the scan spec
scanSpec
)

Split a path on File.pathSeparator (':' on Linux, ';' on Windows), but also allow for the use of URLs with protocol specifiers, e.g. "http://domain/jar1.jar:http://domain/jar2.jar".

public static String[]

Returns:

The path element substrings.
smartPathSplit
(final String
The path to split.
pathStr
,
final char
The separator char to use.
separatorChar
,
final ScanSpec
the scan spec
scanSpec
)

Split a path on the given separator char.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DASH_VERSIONback to summary
private static final Pattern DASH_VERSION

The Constant DASH_VERSION.

LEADING_DOTSback to summary
private static final Pattern LEADING_DOTS

The Constant LEADING_DOTS.

NON_ALPHANUMback to summary
private static final Pattern NON_ALPHANUM

The Constant NON_ALPHANUM.

REPEATING_DOTSback to summary
private static final Pattern REPEATING_DOTS

The Constant REPEATING_DOTS.

TRAILING_DOTSback to summary
private static final Pattern TRAILING_DOTS

The Constant TRAILING_DOTS.

UNIX_NON_PATH_SEPARATOR_COLON_POSITIONSback to summary
private static final int[] UNIX_NON_PATH_SEPARATOR_COLON_POSITIONS

The position of the colon characters in the corresponding UNIX_NON_PATH_SEPARATORS array entry.

UNIX_NON_PATH_SEPARATORSback to summary
private static final String[] UNIX_NON_PATH_SEPARATORS

On everything but Windows, where the path separator is ':', need to treat the colon in these substrings as non-separators, when at the beginning of the string or following a ':'.

URL_SCHEME_PATTERNback to summary
public static final Pattern URL_SCHEME_PATTERN

Check if a path has a URL scheme at the beginning. Require at least 2 chars in a URL scheme, so that Windows drive designations don't get treated as URL schemes.

Constructor Detail

JarUtilsback to summary
private JarUtils()

Constructor.

Method Detail

appendPathEltback to summary
private static void appendPathElt(final Object pathElt, final StringBuilder buf)

Append a path element to a buffer.

Parameters
pathElt:Object

the path element

buf:StringBuilder

the buf

classfilePathToClassNameback to summary
public static String classfilePathToClassName(final String classfilePath)

Convert a classfile path to the corresponding class name.

Parameters
classfilePath:String

the classfile path

Returns:String

the class name

classNameToClassfilePathback to summary
public static String classNameToClassfilePath(final String className)

Convert a class name to the corresponding classfile path.

Parameters
className:String

the class name

Returns:String

the classfile path

derivedAutomaticModuleNameback to summary
public static String derivedAutomaticModuleName(final String jarPath)

Derive automatic module name from jar name, using this algorithm.

Parameters
jarPath:String

The jar path.

Returns:String

The automatic module name.

leafNameback to summary
public static String leafName(final String path)

Returns the leafname of a path, after first stripping off everything after the first '!', if present.

Parameters
path:String

A file path.

Returns:String

The leafname of the path.

pathElementsToPathStrback to summary
public static String pathElementsToPathStr(final Object... pathElts)

Get a set of path elements as a string, from an array of objects (e.g. of String, File or URL type, whose toString() method will be called to get the path component), and return the path as a single string delineated with the standard path separator character.

Parameters
pathElts:Object[]

The path elements.

Returns:String

The delimited path formed out of the path elements.

pathElementsToPathStrback to summary
public static String pathElementsToPathStr(final Iterable<?> pathElts)

Get a set of path elements as a string, from an array of objects (e.g. of String, File or URL type, whose toString() method will be called to get the path component), and return the path as a single string delineated with the standard path separator character.

Parameters
pathElts:Iterable<?>

The path elements.

Returns:String

The delimited path formed out of the path elements, after calling each of their toString() methods.

smartPathSplitback to summary
public static String[] smartPathSplit(final String pathStr, final ScanSpec scanSpec)

Split a path on File.pathSeparator (':' on Linux, ';' on Windows), but also allow for the use of URLs with protocol specifiers, e.g. "http://domain/jar1.jar:http://domain/jar2.jar".

Parameters
pathStr:String

The path to split.

scanSpec:ScanSpec

the scan spec

Returns:String[]

The path element substrings.

smartPathSplitback to summary
public static String[] smartPathSplit(final String pathStr, final char separatorChar, final ScanSpec scanSpec)

Split a path on the given separator char. If the separator char is ':', also allow for the use of URLs with protocol specifiers, e.g. "http://domain/jar1.jar:http://domain/jar2.jar".

Parameters
pathStr:String

The path to split.

separatorChar:char

The separator char to use.

scanSpec:ScanSpec

the scan spec

Returns:String[]

The path element substrings.