Top Inners Fields Constructors Methods
com.jogamp.common.util

public Class JarUtil

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .BufferedOutputStream, .File, .FileOutputStream, .IOException, .InputStream, .OutputStream, java.net.JarURLConnection, .URISyntaxException, .URL, .URLConnection, java.security.cert.Certificate, java.util.Enumeration, .HashMap, .Map, java.util.jar.JarEntry, .JarFile, com.jogamp.common.net.Uri, com.jogamp.common.os.NativeLibrary, .Platform, jogamp.common.Debug

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
JarUtil.Resolver

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

Field Summary

Modifier and TypeField and Description
private static final int
private static final boolean
private static JarUtil.Resolver

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static final int
extract(final File dest, final Map<String, String> nativeLibMap, final JarFile jarFile, final String
if not null, only extracts native libraries within this path.
nativeLibraryPath
,
final boolean extractNativeLibraries, final boolean extractClassFiles, final boolean extractOtherFiles)

Extract the files of the given jar file.

private static final void
fixNativeLibAttribs(final File file)

Mitigate file permission issues of native library files, i.e.:

  • Bug 865: Safari >= 6.1 [OSX]: May employ xattr on 'com.apple.quarantine' on 'PluginProcess.app'
private static native boolean
public static Uri.Encoded

Returns:

gluegen-rt.jar
getJarBasename
(final Uri
as retrieved w/ getJarUri("com.jogamp.common.GlueGenVersion", cl), i.e. jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
classJarUri
)

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.

public static Uri.Encoded

Returns:

gluegen-rt.jar
getJarBasename
(final String
com.jogamp.common.GlueGenVersion
clazzBinName
,
final ClassLoader cl)

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.

public static Uri.Encoded

Returns:

/com/jogamp/common/GlueGenVersion.class
getJarEntry
(final Uri
as retrieved w/ getJarUri("com.jogamp.common.GlueGenVersion", cl), i.e. jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
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.

public static Uri

Returns:

jar:file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
getJarEntryUri
(final Uri
jar:file:/some/path/gluegen-rt.jar!/
jarFileUri
,
final Uri.Encoded
com/jogamp/common/GlueGenVersion.class
jarEntry
)

public static JarFile

Returns:

JarFile containing the named class within the given ClassLoader
getJarFile
(final String
com.jogamp.common.util.cache.TempJarCache
clazzBinName
,
final ClassLoader
domain
cl
)

public static JarFile

Returns:

JarFile as named by Uri within the given ClassLoader
getJarFile
(final Uri
jar:file:/some/path/gluegen-rt.jar!/
jarFileUri
)

public static Uri

Returns:

"jar:sub_protocol:/some/path/gluegen-rt.jar!/"
getJarFileUri
(final String
"com.jogamp.common.GlueGenVersion"
clazzBinName
,
final ClassLoader cl)

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.

public static Uri

Returns:

jar:file:/some/path/gluegen-rt.jar!/
getJarFileUri
(final Uri
file:/some/path/
baseUri
,
final Uri.Encoded
gluegen-rt.jar (Uri encoded)
jarFileName
)

public static Uri

Returns:

jar:file:/some/path/gluegen-rt.jar!/
getJarFileUri
(final Uri
file:/some/path/gluegen-rt.jar
jarSubUri
)

public static Uri

Returns:

jar:file:/some/path/gluegen-rt.jar!/
getJarFileUri
(final Uri.Encoded
file:/some/path/gluegen-rt.jar (Uri encoded)
jarSubUriS
)

public static Uri

Returns:

"jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"
getJarUri
(final String
"com.jogamp.common.GlueGenVersion"
clazzBinName
,
final ClassLoader
ClassLoader to locate the JarFile
cl
)

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

public static Map<String, String>
getNativeLibNames(final JarFile jarFile)

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

public static URI
public static Uri

Returns:

The resulting resource Uri, which is not tested.
getRelativeOf
(final Class<?>
Used to get the root Uri for the class's Jar Uri.
classFromJavaJar
,
final Uri.Encoded
The cut off included sub-directory prepending the relative resource path. If the root Uri includes cutOffInclSubDir, it is no more added to the result.
cutOffInclSubDir
,
final Uri.Encoded
The relative resource path. (Uri encoded)
relResPath
)

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

public static boolean

Returns:

true if the class is loaded from a Jar file, otherwise false.
hasJarUri
(final String
"com.jogamp.common.GlueGenVersion"
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".

public static void
setResolver(final JarUtil.Resolver
Resolver to use after querying class file URLs from the classloader.
r
)

Setting a custom Resolver instance.

private static final void
validateCertificate(final Certificate[] rootCerts, final JarFile jar, final JarEntry entry, final byte[] buf)

Check the certificates with the ones in the jar file (all must match).

public static final void
validateCertificates(final Certificate[] rootCerts, final JarFile jarFile)

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE
DEBUGback to summary
private static final boolean DEBUG
resolverback to summary
private static JarUtil.Resolver resolver

Constructor Detail

JarUtilback to summary
public JarUtil()

Method Detail

extractback to summary
public 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.

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

if not null, only extracts native libraries within this path.

fixNativeLibAttribsback to summary
private static final void fixNativeLibAttribs(final File file)

Mitigate file permission issues of native library files, i.e.:

  • Bug 865: Safari >= 6.1 [OSX]: May employ xattr on 'com.apple.quarantine' on 'PluginProcess.app'
fixNativeLibAttribsback to summary
private static native boolean fixNativeLibAttribs(String fname)
getJarBasenameback to summary
public 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.

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

Parameters
classJarUri:Uri

as retrieved w/ getJarUri("com.jogamp.common.GlueGenVersion", cl), i.e. jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class

Returns:Uri.Encoded

gluegen-rt.jar

Exceptions
IllegalArgumentException:
if the Uri doesn't match the expected formatting or is null
See Also
IOUtil#getClassURL(String, ClassLoader)
getJarBasenameback to summary
public 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.

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

Parameters
clazzBinName:String

com.jogamp.common.GlueGenVersion

Returns:Uri.Encoded

gluegen-rt.jar

Exceptions
IllegalArgumentException:
if the Uri doesn't match the expected formatting
IOException:
if the class's Jar file could not been found by the ClassLoader.
URISyntaxException:
if the Uri could not be translated into a RFC 2396 Uri
See Also
IOUtil#getClassURL(String, ClassLoader)
getJarEntryback to summary
public 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.

Parameters
classJarUri:Uri

as retrieved w/ getJarUri("com.jogamp.common.GlueGenVersion", cl), i.e. jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class

Returns:Uri.Encoded

/com/jogamp/common/GlueGenVersion.class

See Also
IOUtil#getClassURL(String, ClassLoader)
getJarEntryUriback to summary
public static Uri getJarEntryUri(final Uri jarFileUri, final Uri.Encoded jarEntry) throws IllegalArgumentException, URISyntaxException
Parameters
jarFileUri:Uri

jar:file:/some/path/gluegen-rt.jar!/

jarEntry:Uri.Encoded

com/jogamp/common/GlueGenVersion.class

Returns:Uri

jar:file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class

Exceptions
IllegalArgumentException:
null arguments
getJarFileback to summary
public static JarFile getJarFile(final String clazzBinName, final ClassLoader cl) throws IOException, IllegalArgumentException, URISyntaxException
Parameters
clazzBinName:String

com.jogamp.common.util.cache.TempJarCache

cl:ClassLoader

domain

Returns:JarFile

JarFile containing the named class within the given ClassLoader

Exceptions
IOException:
if the class's Jar file could not been found by the ClassLoader
IllegalArgumentException:
null arguments
URISyntaxException:
if the Uri could not be translated into a RFC 2396 Uri
See Also
getJarFileUri(String, ClassLoader)
getJarFileback to summary
public static JarFile getJarFile(final Uri jarFileUri) throws IOException, IllegalArgumentException, URISyntaxException
Parameters
jarFileUri:Uri

jar:file:/some/path/gluegen-rt.jar!/

Returns:JarFile

JarFile as named by Uri within the given ClassLoader

Exceptions
IOException:
if the Jar file could not been found
IllegalArgumentException:
null arguments
getJarFileUriback to summary
public 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.

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

Parameters
clazzBinName:String

"com.jogamp.common.GlueGenVersion"

Returns:Uri

"jar:sub_protocol:/some/path/gluegen-rt.jar!/"

Exceptions
IllegalArgumentException:
if the Uri doesn't match the expected formatting or null arguments
IOException:
if the class's Jar file could not been found by the ClassLoader
URISyntaxException:
if the Uri could not be translated into a RFC 2396 Uri
See Also
IOUtil#getClassURL(String, ClassLoader)
getJarFileUriback to summary
public static Uri getJarFileUri(final Uri baseUri, final Uri.Encoded jarFileName) throws IllegalArgumentException, URISyntaxException
Parameters
baseUri:Uri

file:/some/path/

jarFileName:Uri.Encoded

gluegen-rt.jar (Uri encoded)

Returns:Uri

jar:file:/some/path/gluegen-rt.jar!/

Exceptions
IllegalArgumentException:
null arguments
getJarFileUriback to summary
public static Uri getJarFileUri(final Uri jarSubUri) throws IllegalArgumentException, URISyntaxException
Parameters
jarSubUri:Uri

file:/some/path/gluegen-rt.jar

Returns:Uri

jar:file:/some/path/gluegen-rt.jar!/

Exceptions
IllegalArgumentException:
null arguments
getJarFileUriback to summary
public static Uri getJarFileUri(final Uri.Encoded jarSubUriS) throws IllegalArgumentException, URISyntaxException
Parameters
jarSubUriS:Uri.Encoded

file:/some/path/gluegen-rt.jar (Uri encoded)

Returns:Uri

jar:file:/some/path/gluegen-rt.jar!/

Exceptions
IllegalArgumentException:
null arguments
getJarUriback to summary
public 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.

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

Parameters
clazzBinName:String

"com.jogamp.common.GlueGenVersion"

cl:ClassLoader

ClassLoader to locate the JarFile

Returns:Uri

"jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"

Exceptions
IllegalArgumentException:
if the Uri doesn't match the expected formatting or null arguments
IOException:
if the class's Jar file could not been found by the ClassLoader
URISyntaxException:
if the Uri could not be translated into a RFC 2396 Uri
See Also
IOUtil#getClassURL(String, ClassLoader)
getNativeLibNamesback to summary
public static Map<String, String> getNativeLibNames(final JarFile jarFile)

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

getRelativeOfback to summary
public static URI getRelativeOf(final Class<?> classFromJavaJar, final String cutOffInclSubDir, final String relResPath) throws IllegalArgumentException, IOException, URISyntaxException

See getRelativeOf(Class, com.jogamp.common.net.Uri.Encoded, com.jogamp.common.net.Uri.Encoded).

Parameters
classFromJavaJar:Class<?>

URI encoded!

cutOffInclSubDir:String

URI encoded!

relResPath:String

URI encoded!

getRelativeOfback to summary
public 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.

  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
classFromJavaJar:Class<?>

Used to get the root Uri for the class's Jar Uri.

cutOffInclSubDir:Uri.Encoded

The cut off included sub-directory prepending the relative resource path. If the root Uri includes cutOffInclSubDir, it is no more added to the result.

relResPath:Uri.Encoded

The relative resource path. (Uri encoded)

Returns:Uri

The resulting resource Uri, which is not tested.

hasJarUriback to summary
public 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".

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

Parameters
clazzBinName:String

"com.jogamp.common.GlueGenVersion"

Returns:boolean

true if the class is loaded from a Jar file, otherwise false.

See Also
getJarUri(String, ClassLoader)
setResolverback to summary
public static void setResolver(final JarUtil.Resolver r) throws IllegalArgumentException, IllegalStateException, SecurityException

Setting a custom Resolver instance.

Parameters
r:JarUtil.Resolver

Resolver to use after querying class file URLs from the classloader.

Exceptions
IllegalArgumentException:
if the passed resolver is null
IllegalStateException:
if the resolver has already been set.
SecurityException:
if the security manager doesn't have the setFactory permission
validateCertificateback to summary
private static final void validateCertificate(final Certificate[] rootCerts, final JarFile jar, final JarEntry entry, final byte[] buf) throws IOException, SecurityException

Check the certificates with the ones in the jar file (all must match).

validateCertificatesback to summary
public static final void validateCertificates(final Certificate[] rootCerts, final JarFile jarFile) throws IOException, SecurityException

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();
      
com.jogamp.common.util back to summary

public Interface JarUtil.Resolver


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

This might be required for custom classloader where the URI protocol is unknown to the standard runtime environment.

Note

The provided resolver is only utilized if a given URI's protocol could not be resolved. I.e. it will not be invoked for known protocols like http, https, jar or file.

Method Summary

Modifier and TypeMethod and Description
public URL
resolve(URL url)

Method Detail

resolveback to summary
public URL resolve(URL url)