jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Classes | Static Public Member Functions | List of all members
org.jau.pkg.JarUtil Class Reference
Collaboration diagram for org.jau.pkg.JarUtil:

Classes

interface  Resolver
 Interface allowing users to provide an URL resolver that will convert custom classloader URLs like Eclipse/OSGi bundleresource: URLs to normal jar: URLs. More...
 

Static Public Member Functions

static void setResolver (final Resolver r) throws IllegalArgumentException, IllegalStateException, SecurityException
 Setting a custom Resolver instance. More...
 
static boolean hasJarUri (final String clazzBinName, final ClassLoader cl)
 Returns true if the Class's "com.jogamp.common.GlueGenVersion" is loaded from a JarFile and hence has a Jar URI like URI jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class". More...
 
static Uri getJarUri (final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException
 The Class's "com.jogamp.common.GlueGenVersion" Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class" will be returned. More...
 
static Uri.Encoded getJarBasename (final Uri classJarUri) throws IllegalArgumentException
 The Class's Jar Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar basename gluegen-rt.jar will be returned. More...
 
static Uri.Encoded getJarBasename (final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException
 The Class's com.jogamp.common.GlueGenVersion Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar basename gluegen-rt.jar will be returned. More...
 
static Uri.Encoded getJarEntry (final Uri classJarUri)
 The Class's Jar Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar file's entry /com/jogamp/common/GlueGenVersion.class will be returned. More...
 
static Uri getJarFileUri (final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException
 The Class's "com.jogamp.common.GlueGenVersion" Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class" Jar file Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/ will be returned. More...
 
static Uri getJarFileUri (final Uri baseUri, final Uri.Encoded jarFileName) throws IllegalArgumentException, URISyntaxException
 
static Uri getJarFileUri (final Uri jarSubUri) throws IllegalArgumentException, URISyntaxException
 
static Uri getJarFileUri (final Uri.Encoded jarSubUriS) throws IllegalArgumentException, URISyntaxException
 
static Uri getJarEntryUri (final Uri jarFileUri, final Uri.Encoded jarEntry) throws IllegalArgumentException, URISyntaxException
 
static JarFile getJarFile (final String clazzBinName, final ClassLoader cl) throws IOException, IllegalArgumentException, URISyntaxException
 
static JarFile getJarFile (final Uri jarFileUri) throws IOException, IllegalArgumentException, URISyntaxException
 
static Uri getRelativeOf (final Class<?> classFromJavaJar, final Uri.Encoded cutOffInclSubDir, final Uri.Encoded relResPath) throws IllegalArgumentException, IOException, URISyntaxException
 Locates the Jar file Uri of a given resource relative to a given class's Jar's Uri. More...
 
static Map< String, String > getNativeLibNames (final JarFile jarFile)
 Return a map from native-lib-base-name to entry-name. More...
 
static final int extract (final File dest, final Map< String, String > nativeLibMap, final JarFile jarFile, final String nativeLibraryPath, final boolean extractNativeLibraries, final boolean extractClassFiles, final boolean extractOtherFiles) throws IOException
 Extract the files of the given jar file. More...
 
static final void validateCertificates (final Certificate[] rootCerts, final JarFile jarFile) throws IOException, SecurityException
 Validate the certificates for each native Lib in the jar file. More...
 

Detailed Description

Definition at line 54 of file JarUtil.java.

Member Function Documentation

◆ extract()

static final int org.jau.pkg.JarUtil.extract ( final File  dest,
final Map< String, String >  nativeLibMap,
final JarFile  jarFile,
final String  nativeLibraryPath,
final boolean  extractNativeLibraries,
final boolean  extractClassFiles,
final boolean  extractOtherFiles 
) throws IOException
static

Extract the files of the given jar file.

If extractNativeLibraries is true, native libraries are added to the given nativeLibMap with the base name to temp file location.
A file is identified as a native library, if it's name complies with the running platform's native library naming scheme.
Root entries are favored over non root entries in case of naming collisions.
Example on a Unix like machine:

  mylib.jar!/sub1/libsour.so   -> sour  (mapped, unique name)
  mylib.jar!/sub1/libsweet.so           (dropped, root entry favored)
  mylib.jar!/libsweet.so       -> sweet (mapped, root entry favored)
  mylib.jar!/sweet.dll         ->       (dropped, not a unix library name)

In order to be compatible with Java Web Start, we need to extract all root entries from the jar file.
In this case, set all flags to true extractNativeLibraries . extractClassFiles, extractOtherFiles.

Parameters
dest
nativeLibMap
jarFile
nativeLibraryPathif not null, only extracts native libraries within this path.
extractNativeLibraries
extractClassFiles
extractOtherFiles
deepDirectoryTraversal
Returns
Exceptions
IOException

Definition at line 541 of file JarUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getJarBasename() [1/2]

static Uri.Encoded org.jau.pkg.JarUtil.getJarBasename ( final String  clazzBinName,
final ClassLoader  cl 
) throws IllegalArgumentException, IOException, URISyntaxException
static

The Class's com.jogamp.common.GlueGenVersion Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar basename gluegen-rt.jar will be returned.

sub_protocol may be "file", "http", etc..

Parameters
clazzBinNamecom.jogamp.common.GlueGenVersion
cl
Returns
gluegen-rt.jar
Exceptions
IllegalArgumentExceptionif the Uri doesn't match the expected formatting
IOExceptionif the class's Jar file could not been found by the ClassLoader.
URISyntaxExceptionif the Uri could not be translated into a RFC 2396 Uri
See also
IOUtil#getClassURL(String, ClassLoader)

Definition at line 249 of file JarUtil.java.

Here is the call graph for this function:

◆ getJarBasename() [2/2]

static Uri.Encoded org.jau.pkg.JarUtil.getJarBasename ( final Uri  classJarUri) throws IllegalArgumentException
static

The Class's Jar Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar basename gluegen-rt.jar will be returned.

sub_protocol may be "file", "http", etc..

Parameters
classJarUrias retrieved w/ getJarUri("com.jogamp.common.GlueGenVersion", cl), i.e. jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
Returns
gluegen-rt.jar
Exceptions
IllegalArgumentExceptionif the Uri doesn't match the expected formatting or is null
See also
IOUtil#getClassURL(String, ClassLoader)

Definition at line 190 of file JarUtil.java.

Here is the caller graph for this function:

◆ getJarEntry()

static Uri.Encoded org.jau.pkg.JarUtil.getJarEntry ( final Uri  classJarUri)
static

The Class's Jar Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class Jar file's entry /com/jogamp/common/GlueGenVersion.class will be returned.

Parameters
classJarUrias retrieved w/ getJarUri("com.jogamp.common.GlueGenVersion", cl), i.e. jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
Returns
/com/jogamp/common/GlueGenVersion.class
See also
IOUtil#getClassURL(String, ClassLoader)

Definition at line 262 of file JarUtil.java.

Here is the call graph for this function:

◆ getJarEntryUri()

static Uri org.jau.pkg.JarUtil.getJarEntryUri ( final Uri  jarFileUri,
final Uri.Encoded  jarEntry 
) throws IllegalArgumentException, URISyntaxException
static
Parameters
jarFileUrijar:file:/some/path/gluegen-rt.jar!/
jarEntrycom/jogamp/common/GlueGenVersion.class
Returns
jar:file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
Exceptions
IllegalArgumentExceptionnull arguments
URISyntaxException

Definition at line 363 of file JarUtil.java.

Here is the call graph for this function:

◆ getJarFile() [1/2]

static JarFile org.jau.pkg.JarUtil.getJarFile ( final String  clazzBinName,
final ClassLoader  cl 
) throws IOException, IllegalArgumentException, URISyntaxException
static
Parameters
clazzBinNamecom.jogamp.common.util.cache.TempJarCache
cldomain
Returns
JarFile containing the named class within the given ClassLoader
Exceptions
IOExceptionif the class's Jar file could not been found by the ClassLoader
IllegalArgumentExceptionnull arguments
URISyntaxExceptionif the Uri could not be translated into a RFC 2396 Uri
See also
getJarFileUri(String, ClassLoader)

Definition at line 379 of file JarUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getJarFile() [2/2]

static JarFile org.jau.pkg.JarUtil.getJarFile ( final Uri  jarFileUri) throws IOException, IllegalArgumentException, URISyntaxException
static
Parameters
jarFileUrijar:file:/some/path/gluegen-rt.jar!/
Returns
JarFile as named by Uri within the given ClassLoader
Exceptions
IllegalArgumentExceptionnull arguments
IOExceptionif the Jar file could not been found
URISyntaxException

Definition at line 390 of file JarUtil.java.

◆ getJarFileUri() [1/4]

static Uri org.jau.pkg.JarUtil.getJarFileUri ( final String  clazzBinName,
final ClassLoader  cl 
) throws IllegalArgumentException, IOException, URISyntaxException
static

The Class's "com.jogamp.common.GlueGenVersion" Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class" Jar file Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/ will be returned.

sub_protocol may be "file", "http", etc..

Parameters
clazzBinName"com.jogamp.common.GlueGenVersion"
cl
Returns
"jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/"
Exceptions
IllegalArgumentExceptionif the Uri doesn't match the expected formatting or null arguments
IOExceptionif the class's Jar file could not been found by the ClassLoader
URISyntaxExceptionif the Uri could not be translated into a RFC 2396 Uri
See also
IOUtil#getClassURL(String, ClassLoader)

Definition at line 304 of file JarUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getJarFileUri() [2/4]

static Uri org.jau.pkg.JarUtil.getJarFileUri ( final Uri  baseUri,
final Uri.Encoded  jarFileName 
) throws IllegalArgumentException, URISyntaxException
static
Parameters
baseUrifile:/some/path/
jarFileNamegluegen-rt.jar (Uri encoded)
Returns
jar:file:/some/path/gluegen-rt.jar!/
Exceptions
URISyntaxException
IllegalArgumentExceptionnull arguments

Definition at line 323 of file JarUtil.java.

Here is the call graph for this function:

◆ getJarFileUri() [3/4]

static Uri org.jau.pkg.JarUtil.getJarFileUri ( final Uri  jarSubUri) throws IllegalArgumentException, URISyntaxException
static
Parameters
jarSubUrifile:/some/path/gluegen-rt.jar
Returns
jar:file:/some/path/gluegen-rt.jar!/
Exceptions
IllegalArgumentExceptionnull arguments
URISyntaxException

Definition at line 336 of file JarUtil.java.

Here is the call graph for this function:

◆ getJarFileUri() [4/4]

static Uri org.jau.pkg.JarUtil.getJarFileUri ( final Uri.Encoded  jarSubUriS) throws IllegalArgumentException, URISyntaxException
static
Parameters
jarSubUriSfile:/some/path/gluegen-rt.jar (Uri encoded)
Returns
jar:file:/some/path/gluegen-rt.jar!/
Exceptions
IllegalArgumentExceptionnull arguments
URISyntaxException

Definition at line 349 of file JarUtil.java.

Here is the call graph for this function:

◆ getJarUri()

static Uri org.jau.pkg.JarUtil.getJarUri ( final String  clazzBinName,
final ClassLoader  cl 
) throws IllegalArgumentException, IOException, URISyntaxException
static

The Class's "com.jogamp.common.GlueGenVersion" Uri jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class" will be returned.

sub_protocol may be "file", "http", etc..

Parameters
clazzBinName"com.jogamp.common.GlueGenVersion"
clClassLoader to locate the JarFile
Returns
"jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"
Exceptions
IllegalArgumentExceptionif the Uri doesn't match the expected formatting or null arguments
IOExceptionif the class's Jar file could not been found by the ClassLoader
URISyntaxExceptionif the Uri could not be translated into a RFC 2396 Uri
See also
IOUtil#getClassURL(String, ClassLoader)

Definition at line 140 of file JarUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNativeLibNames()

static Map< String, String > org.jau.pkg.JarUtil.getNativeLibNames ( final JarFile  jarFile)
static

Return a map from native-lib-base-name to entry-name.

Definition at line 485 of file JarUtil.java.

Here is the call graph for this function:

◆ getRelativeOf()

static Uri org.jau.pkg.JarUtil.getRelativeOf ( final Class<?>  classFromJavaJar,
final Uri.Encoded  cutOffInclSubDir,
final Uri.Encoded  relResPath 
) throws IllegalArgumentException, IOException, URISyntaxException
static

Locates the Jar file Uri of a given resource relative to a given class's Jar's Uri.

  class's jar url path + cutOffInclSubDir + relResPath,

Example #1

  classFromJavaJar = com.lighting.Test (in: file:/storage/TestLighting.jar)
  cutOffInclSubDir = lights/
  relResPath       = LightAssets.jar
  Result           : file:/storage/lights/LightAssets.jar

Example #2

  classFromJavaJar = com.lighting.Test (in: file:/storage/lights/TestLighting.jar)
  cutOffInclSubDir = lights/
  relResPath       = LightAssets.jar
  Result           : file:/storage/lights/LightAssets.jar

TODO: Enhance documentation!

Parameters
classFromJavaJarUsed to get the root Uri for the class's Jar Uri.
cutOffInclSubDirThe cut off included sub-directory prepending the relative resource path. If the root Uri includes cutOffInclSubDir, it is no more added to the result.
relResPathThe relative resource path. (Uri encoded)
Returns
The resulting resource Uri, which is not tested.
Exceptions
IllegalArgumentException
IOException
URISyntaxException

Definition at line 448 of file JarUtil.java.

Here is the call graph for this function:

◆ hasJarUri()

static boolean org.jau.pkg.JarUtil.hasJarUri ( final String  clazzBinName,
final ClassLoader  cl 
)
static

Returns true if the Class's "com.jogamp.common.GlueGenVersion" is loaded from a JarFile and hence has a Jar URI like URI jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class".

sub_protocol may be "file", "http", etc..

Parameters
clazzBinName"com.jogamp.common.GlueGenVersion"
cl
Returns
true if the class is loaded from a Jar file, otherwise false.
See also
getJarUri(String, ClassLoader)

Definition at line 117 of file JarUtil.java.

Here is the call graph for this function:

◆ setResolver()

static void org.jau.pkg.JarUtil.setResolver ( final Resolver  r) throws IllegalArgumentException, IllegalStateException, SecurityException
static

Setting a custom Resolver instance.

Parameters
rResolver to use after querying class file URLs from the classloader.
Exceptions
IllegalArgumentExceptionif the passed resolver is null
IllegalStateExceptionif the resolver has already been set.
SecurityExceptionif the security manager doesn't have the setFactory permission

Definition at line 87 of file JarUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateCertificates()

static final void org.jau.pkg.JarUtil.validateCertificates ( final Certificate[]  rootCerts,
final JarFile  jarFile 
) throws IOException, SecurityException
static

Validate the certificates for each native Lib in the jar file.

Throws an IOException if any certificate is not valid.

 Certificate[] rootCerts = Something.class.getProtectionDomain().
                                 getCodeSource().getCertificates();

Definition at line 688 of file JarUtil.java.


The documentation for this class was generated from the following file: