From 4376174ad35fdaf76f59430328582e913f468674 Mon Sep 17 00:00:00 2001
From: Sven Gothel
+ * protocol may be "file", "http", etc..
+ *
+ * The folloing cases are considered:
+ * java.io.tmpdir
*/
- public static final String java_io_tmpdir_propkey = "java.io.tmpdir";
- public static final String user_home_propkey = "user.home";
+ /** Std. temporary directory property key java.io.tmpdir
. */
+ private static final String java_io_tmpdir_propkey = "java.io.tmpdir";
+ private static final String user_home_propkey = "user.home";
private static final String XDG_CACHE_HOME_envkey = "XDG_CACHE_HOME";
/** Subdirectory within platform's temporary root directory where all JogAmp related temp files are being stored: {@code jogamp} */
@@ -300,7 +308,7 @@ public class IOUtil {
public static URI toURISimple(String protocol, String file, boolean isDirectory) throws URISyntaxException {
return new URI(protocol, null, slashify(file, true, isDirectory), null);
}
-
+
/**
* Returns the lowercase suffix of the given file name (the text
* after the last '.' in the file name). Returns null if the file
@@ -333,7 +341,14 @@ public class IOUtil {
}
return toLowerCase(filename.substring(lastDot + 1));
}
+ private static String toLowerCase(String arg) {
+ if (arg == null) {
+ return null;
+ }
+ return arg.toLowerCase();
+ }
+
/***
* @param file
* @param allowOverwrite
@@ -402,14 +417,88 @@ public class IOUtil {
return fname;
}
- private static String toLowerCase(String arg) {
- if (arg == null) {
- return null;
+ /**
+ * The URI's protocol:/some/path/gluegen-rt.jar
+ * parent dirname URI protocol:/some/path/
will be returned.
+ * file:/
.
+ * Otherwise the default {@link URL} translation {@link URI#toURL()} is being used.
+ *
+ *
+ * new File(uri).getPath()
.
+ *
jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
- * @param cl
* @return sub_protocol:/some/path/gluegen-rt.jar
* @throws IllegalArgumentException if the URI doesn't match the expected formatting or is null
* @throws URISyntaxException if the URI could not be translated into a RFC 2396 URI
@@ -286,6 +285,36 @@ public class JarUtil {
}
return new URI(uriS);
}
+
+ /**
+ * 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.
+ *
+ * @param classJarURI as retrieved w/ {@link #getJarURI(String, ClassLoader) getJarURI("com.jogamp.common.GlueGenVersion", cl).toURI()},
+ * i.e. jar:sub_protocol:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
+ * @return /com/jogamp/common/GlueGenVersion.class
+ * @see {@link IOUtil#getClassURL(String, ClassLoader)}
+ */
+ public static String getJarEntry(URI classJarURI) {
+ if(null == classJarURI) {
+ throw new IllegalArgumentException("URI is null");
+ }
+ if( !classJarURI.getScheme().equals(IOUtil.JAR_SCHEME) ) {
+ throw new IllegalArgumentException("URI is not a using scheme "+IOUtil.JAR_SCHEME+": <"+classJarURI+">");
+ }
+ String uriS = classJarURI.getRawSchemeSpecificPart();
+
+ // from
+ // file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class
+ // to
+ // file:/some/path/gluegen-rt.jar
+ int idx = uriS.lastIndexOf('!');
+ if (0 <= idx) {
+ return uriS.substring(idx+1); // right of '!'
+ } else {
+ throw new IllegalArgumentException("JAR URI does not contain jar uri terminator '!', uri <"+classJarURI+">");
+ }
+ }
/**
* The Class's com.jogamp.common.GlueGenVersion
@@ -334,46 +363,6 @@ public class JarUtil {
return uri;
}
- /**
- * The URI's protocol:/some/path/gluegen-rt.jar
- * parent dirname URI protocol:/some/path/
will be returned.
- * - * protocol may be "file", "http", etc.. - *
- * - * @param aURI "protocol:/some/path/gluegen-rt.jar" - * @return "protocol:/some/path/" - * @throws IllegalArgumentException if the URI doesn't match the expected formatting, or is null - * @throws URISyntaxException - */ - public static URI getURIDirname(URI aURI) throws IllegalArgumentException, URISyntaxException { - if(null == aURI) { - throw new IllegalArgumentException("URI is null"); - } - String uriS = aURI.toString(); - if(DEBUG) { - System.out.println("getURIDirname "+aURI+", extForm: "+uriS); - } - // from - // file:/some/path/gluegen-rt.jar _or_ rsrc:gluegen-rt.jar - // to - // file:/some/path/ _or_ rsrc: - int idx = uriS.lastIndexOf('/'); - if(0 > idx) { - // no abs-path, check for protocol terminator ':' - idx = uriS.lastIndexOf(':'); - if(0 > idx) { - throw new IllegalArgumentException("URI does not contain protocol terminator ':', in <"+aURI+">"); - } - } - uriS = uriS.substring(0, idx+1); // exclude jar name, include terminal '/' or ':' - - if(DEBUG) { - System.out.println("getJarURIDirname res: "+uriS); - } - return new URI(uriS); - } - /** * @param baseUri file:/some/path/ * @param jarFileName gluegen-rt.jar @@ -433,15 +422,17 @@ public class JarUtil { * @return JarFile as named by URI within the given ClassLoader * @throws IllegalArgumentException null arguments * @throws IOException if the Jar file could not been found + * @throws URISyntaxException */ - public static JarFile getJarFile(URI jarFileURI) throws IOException, IllegalArgumentException { + public static JarFile getJarFile(URI jarFileURI) throws IOException, IllegalArgumentException, URISyntaxException { if(null == jarFileURI) { throw new IllegalArgumentException("null jarFileURI"); } if(DEBUG) { - System.out.println("getJarFile: "+jarFileURI); + System.out.println("getJarFile: "+jarFileURI.toString()); } - final URL jarFileURL = jarFileURI.toURL(); + final URL jarFileURL = IOUtil.toURL(jarFileURI); + // final URL jarFileURL = jarFileURI.toURL(); // doesn't work due to encoded path even w/ file schema! final URLConnection urlc = jarFileURL.openConnection(); if(urlc instanceof JarURLConnection) { JarURLConnection jarConnection = (JarURLConnection)jarFileURL.openConnection(); diff --git a/src/java/com/jogamp/common/util/cache/TempJarCache.java b/src/java/com/jogamp/common/util/cache/TempJarCache.java index b17dd52..4c505f9 100644 --- a/src/java/com/jogamp/common/util/cache/TempJarCache.java +++ b/src/java/com/jogamp/common/util/cache/TempJarCache.java @@ -206,8 +206,10 @@ public class TempJarCache { * @param jarURI * @throws IOException if thejarURI
could not be loaded or a previous load attempt failed
* @throws SecurityException
+ * @throws URISyntaxException
+ * @throws IllegalArgumentException
*/
- public synchronized static final void addNativeLibs(Class> certClass, URI jarURI) throws IOException, SecurityException {
+ public synchronized static final void addNativeLibs(Class> certClass, URI jarURI) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException {
final LoadState nativeLibJarsLS = nativeLibJars.get(jarURI);
if( !testLoadState(nativeLibJarsLS, LoadState.LOOKED_UP) ) {
nativeLibJars.put(jarURI, LoadState.LOOKED_UP);
@@ -233,8 +235,10 @@ public class TempJarCache {
* @param jarURI
* @throws IOException if the jarURI
could not be loaded or a previous load attempt failed
* @throws SecurityException
+ * @throws URISyntaxException
+ * @throws IllegalArgumentException
*/
- public synchronized static final void addClasses(Class> certClass, URI jarURI) throws IOException, SecurityException {
+ public synchronized static final void addClasses(Class> certClass, URI jarURI) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException {
final LoadState classFileJarsLS = classFileJars.get(jarURI);
if( !testLoadState(classFileJarsLS, LoadState.LOOKED_UP) ) {
classFileJars.put(jarURI, LoadState.LOOKED_UP);
@@ -259,8 +263,10 @@ public class TempJarCache {
* @return
* @throws IOException if the jarURI
could not be loaded or a previous load attempt failed
* @throws SecurityException
+ * @throws URISyntaxException
+ * @throws IllegalArgumentException
*/
- public synchronized static final void addResources(Class> certClass, URI jarURI) throws IOException, SecurityException {
+ public synchronized static final void addResources(Class> certClass, URI jarURI) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException {
final LoadState resourceFileJarsLS = resourceFileJars.get(jarURI);
if( !testLoadState(resourceFileJarsLS, LoadState.LOOKED_UP) ) {
resourceFileJars.put(jarURI, LoadState.LOOKED_UP);
@@ -288,8 +294,10 @@ public class TempJarCache {
* @param jarURI
* @throws IOException if the jarURI
could not be loaded or a previous load attempt failed
* @throws SecurityException
+ * @throws URISyntaxException
+ * @throws IllegalArgumentException
*/
- public synchronized static final void addAll(Class> certClass, URI jarURI) throws IOException, SecurityException {
+ public synchronized static final void addAll(Class> certClass, URI jarURI) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException {
checkInitialized();
if(null == jarURI) {
throw new IllegalArgumentException("jarURI is null");
@@ -400,9 +408,11 @@ public class TempJarCache {
*
* @throws IOException
* @throws SecurityException
+ * @throws URISyntaxException
+ * @throws IllegalArgumentException
*/
public synchronized static final void bootstrapNativeLib(Class> certClass, String libBaseName, URI jarURI)
- throws IOException, SecurityException {
+ throws IOException, SecurityException, IllegalArgumentException, URISyntaxException {
checkInitialized();
boolean ok = false;
int countEntries = 0;
--
cgit v1.2.3