Class JarUtils
- java.lang.Object
-
- io.github.fastclasspathscanner.utils.JarUtils
-
public class JarUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String[]
SYSTEM_PACKAGE_PATH_PREFIXES
Prefixes of system (JRE) packages, turned into path form (with slashes instead of dots).static String[]
SYSTEM_PACKAGE_PREFIXES
Prefixes of system (JRE) packages.
-
Constructor Summary
Constructors Constructor Description JarUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
countBytesBeforePKMarker(File zipfile)
Count the number of bytes before the characters "PK" in a zipfile.static ClassLoader
createURLClassLoaderFromPathString(String classpathStr)
Create a custom URLClassLoader from a classpath path string.static List<String>
getJreJarPaths()
Get the paths of jars in all JRE/JDK system directories, with any rt.jar listed first.static Set<String>
getJreLibOrExtJars()
Get the paths for any JRE/JDK "lib/" or "ext/" jars.static boolean
isInSystemPackageOrModule(String packageOrModuleName)
Return true if the given class name, package name or module name has a system package or module prefixstatic boolean
isJREJar(String filePath, ScanSpec scanSpec, LogNode log)
Determine whether a given jarfile is in a JRE system directory (jre, jre/lib, jre/lib/ext, etc.).static String
leafName(String path)
Returns the leafname of a path, after first stripping off everything after the first '!', if present.static void
logJavaInfo(LogNode log)
Log the Java version and the JRE paths that were found.static String
pathElementsToPathStr(Iterable<?> pathElts)
Get a set of path elements as a string, from an array of objects (e.g.static String
pathElementsToPathStr(Object... pathElts)
Get a set of path elements as a string, from an array of objects (e.g.static String[]
smartPathSplit(String pathStr)
Split a path on File.pathSeparator (':' on Linux, ';' on Windows), but also allow for the use of URLs with protocol specifiers, e.g.static void
stripSFXHeader(File srcZipfile, long sfxHeaderBytes, File destZipfile)
Strip the self-extracting archive header from the beginning of a zipfile.
-
-
-
Field Detail
-
SYSTEM_PACKAGE_PREFIXES
public static final String[] SYSTEM_PACKAGE_PREFIXES
Prefixes of system (JRE) packages.
-
SYSTEM_PACKAGE_PATH_PREFIXES
public static final String[] SYSTEM_PACKAGE_PATH_PREFIXES
Prefixes of system (JRE) packages, turned into path form (with slashes instead of dots).
-
-
Method Detail
-
smartPathSplit
public static String[] smartPathSplit(String pathStr)
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". This is really not even handled by the JRE, in all likelihood, but it's better to be robust.
-
createURLClassLoaderFromPathString
public static ClassLoader createURLClassLoaderFromPathString(String classpathStr)
Create a custom URLClassLoader from a classpath path string.
-
pathElementsToPathStr
public static String pathElementsToPathStr(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.- Returns:
- the delimited path.
-
pathElementsToPathStr
public static String pathElementsToPathStr(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.- Returns:
- the delimited path.
-
leafName
public static String leafName(String path)
Returns the leafname of a path, after first stripping off everything after the first '!', if present.
-
getJreJarPaths
public static List<String> getJreJarPaths()
Get the paths of jars in all JRE/JDK system directories, with any rt.jar listed first.
-
getJreLibOrExtJars
public static Set<String> getJreLibOrExtJars()
Get the paths for any JRE/JDK "lib/" or "ext/" jars.
-
isJREJar
public static boolean isJREJar(String filePath, ScanSpec scanSpec, LogNode log)
Determine whether a given jarfile is in a JRE system directory (jre, jre/lib, jre/lib/ext, etc.).
-
isInSystemPackageOrModule
public static boolean isInSystemPackageOrModule(String packageOrModuleName)
Return true if the given class name, package name or module name has a system package or module prefix
-
countBytesBeforePKMarker
public static long countBytesBeforePKMarker(File zipfile) throws IOException
Count the number of bytes before the characters "PK" in a zipfile. Returns -1 if PK is not found anywhere in the file.- Throws:
IOException
-
stripSFXHeader
public static void stripSFXHeader(File srcZipfile, long sfxHeaderBytes, File destZipfile) throws IOException
Strip the self-extracting archive header from the beginning of a zipfile.- Throws:
IOException
-
logJavaInfo
public static void logJavaInfo(LogNode log)
Log the Java version and the JRE paths that were found.
-
-