diff options
Diffstat (limited to 'src/java/com/jogamp/common/util')
-rw-r--r-- | src/java/com/jogamp/common/util/IOUtil.java | 330 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/JarUtil.java | 301 | ||||
-rw-r--r-- | src/java/com/jogamp/common/util/cache/TempJarCache.java | 156 |
3 files changed, 242 insertions, 545 deletions
diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 5819fbc..3a09835 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -40,7 +40,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; import java.lang.reflect.Constructor; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; @@ -52,6 +51,7 @@ import jogamp.common.os.AndroidUtils; import jogamp.common.os.PlatformPropsImpl; import com.jogamp.common.net.AssetURLContext; +import com.jogamp.common.net.Uri; import com.jogamp.common.nio.Buffers; import com.jogamp.common.os.MachineDescription; import com.jogamp.common.os.Platform; @@ -59,19 +59,6 @@ import com.jogamp.common.os.Platform; public class IOUtil { public static final boolean DEBUG = Debug.debug("IOUtil"); - /** {@value} */ - public static final String SCHEME_SEPARATOR = ":"; - /** {@value} */ - public static final String FILE_SCHEME = "file"; - /** {@value} */ - public static final String HTTP_SCHEME = "http"; - /** {@value} */ - public static final String HTTPS_SCHEME = "https"; - /** {@value} */ - public static final String JAR_SCHEME = "jar"; - /** A JAR subprotocol is separeted from the JAR entry w/ this separator {@value}. Even if no class is specified '!/' must follow!. */ - public static final char JAR_SCHEME_SEPARATOR = '!'; - /** Std. temporary directory property key <code>java.io.tmpdir</code>. */ private static final String java_io_tmpdir_propkey = "java.io.tmpdir"; private static final String user_home_propkey = "user.home"; @@ -289,6 +276,8 @@ public class IOUtil { * */ + private static final Pattern patternSingleBS = Pattern.compile("\\\\{1}"); + /** * * @param path @@ -298,7 +287,7 @@ public class IOUtil { * @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code> */ public static String slashify(final String path, final boolean startWithSlash, final boolean endWithSlash) throws URISyntaxException { - String p = path.replace('\\', '/'); // unify file separator + String p = patternSingleBS.matcher(path).replaceAll("/"); if (startWithSlash && !p.startsWith("/")) { p = "/" + p; } @@ -309,24 +298,6 @@ public class IOUtil { } /** - * Using the simple conversion via File -> URI, assuming proper characters. - * @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code> - * @throws URISyntaxException if the resulting string does not comply w/ an RFC 2396 URI - */ - public static URI toURISimple(final File file) throws URISyntaxException { - return new URI(FILE_SCHEME, null, slashify(file.getAbsolutePath(), true /* startWithSlash */, file.isDirectory() /* endWithSlash */), null); - } - - /** - * Using the simple conversion via File -> URI, assuming proper characters. - * @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code> - * @throws URISyntaxException if the resulting string does not comply w/ an RFC 2396 URI - */ - public static URI toURISimple(final String protocol, final String path, final boolean isDirectory) throws URISyntaxException { - return new URI(protocol, null, slashify(new File(path).getAbsolutePath(), true /* startWithSlash */, isDirectory /* endWithSlash */), null); - } - - /** * Returns the lowercase suffix of the given file name (the text * after the last '.' in the file name). Returns null if the file * name has no suffix. Only operates on the given file name; @@ -434,79 +405,6 @@ public class IOUtil { return fname; } - /** - * The URI's <code><i>protocol</i>:/some/path/gluegen-rt.jar</code> - * parent dirname URI <code><i>protocol</i>:/some/path/</code> will be returned. - * <p> - * <i>protocol</i> may be "file", "http", etc.. - * </p> - * - * @param uri "<i>protocol</i>:/some/path/gluegen-rt.jar" - * @return "<i>protocol</i>:/some/path/" - * @throws IllegalArgumentException if the URI doesn't match the expected formatting, or is null - * @throws URISyntaxException - */ - public static URI getURIDirname(final URI uri) throws IllegalArgumentException, URISyntaxException { - if(null == uri) { - throw new IllegalArgumentException("URI is null"); - } - final String uriS = uri.toString(); - if( DEBUG ) { - System.err.println("getURIDirname "+uri+", extForm: "+uriS); - } - return new URI( getURIDirname(uriS) ); - } - - /** - * The URI's <code><i>protocol</i>:/some/path/gluegen-rt.jar</code> - * parent dirname URI <code><i>protocol</i>:/some/path/</code> will be returned. - * <p> - * <i>protocol</i> may be "file", "http", etc.. - * </p> - * - * @param uri "<i>protocol</i>:/some/path/gluegen-rt.jar" (URI encoded) - * @return "<i>protocol</i>:/some/path/" - * @throws IllegalArgumentException if the URI doesn't match the expected formatting, or is null - * @throws URISyntaxException - */ - public static String getURIDirname(String uriS) throws IllegalArgumentException, URISyntaxException { - if(null == uriS) { - throw new IllegalArgumentException("uriS is null"); - } - // 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 <"+uriS+">"); - } - } - uriS = uriS.substring(0, idx+1); // exclude jar name, include terminal '/' or ':' - - if( DEBUG ) { - System.err.println("getJarURIDirname res: "+uriS); - } - return uriS; - } - - /** - * Simply returns {@link URI#toURL()}. - * @param uri - * @return - * @throws IOException - * @throws IllegalArgumentException - * @throws URISyntaxException - * - * @deprecated Useless - */ - public static URL toURL(final URI uri) throws IOException, IllegalArgumentException, URISyntaxException { - return uri.toURL(); - } - /*** * * RESOURCE LOCATION STUFF @@ -638,6 +536,20 @@ public class IOUtil { } /** + * Wraps {@link #getRelativeOf(URI, String)} for convenience. + * @param relativePath denotes a relative file to the baseLocation's parent directory (URI encoded) + * @throws IOException + * @deprecated Use {@link Uri#getRelativeOf(com.jogamp.common.net.Uri.Encoded)}. + */ + public static URL getRelativeOf(final URL baseURL, final String relativePath) throws IOException { + try { + return Uri.valueOf(baseURL).getRelativeOf(Uri.Encoded.cast(relativePath)).toURL(); + } catch (final URISyntaxException e) { + throw new IOException(e); + } + } + + /** * Generates a path for the 'relativeFile' relative to the 'baseLocation'. * * @param baseLocation denotes a directory @@ -705,177 +617,7 @@ public class IOUtil { return path; } - /** - * Generates a URI for the <i>relativePath</i> relative to the <i>baseURI</i>, - * hence the result is a absolute location. - * <p> - * Impl. operates on the <i>scheme-specific-part</i>, and hence is sub-protocol savvy. - * </p> - * <p> - * In case <i>baseURI</i> is not a path ending w/ '/', it's a assumed to be a file and it's parent is being used. - * </p> - * - * @param baseURI denotes a URI to a directory ending w/ '/', or a file. In the latter case the file's directory is being used. - * @param relativePath denotes a relative file to the baseLocation's parent directory (URI encoded) - * @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code> - */ - public static URI getRelativeOf(final URI baseURI, final String relativePath) throws URISyntaxException { - return compose(baseURI.getScheme(), baseURI.getRawSchemeSpecificPart(), relativePath, baseURI.getRawFragment()); - } - - /** - * Wraps {@link #getRelativeOf(URI, String)} for convenience. - * @param relativePath denotes a relative file to the baseLocation's parent directory (URI encoded) - * @throws IOException - */ - public static URL getRelativeOf(final URL baseURL, final String relativePath) throws IOException { - try { - return getRelativeOf(baseURL.toURI(), relativePath).toURL(); - } catch (final URISyntaxException e) { - throw new IOException(e); - } - } - - /** - * Generates a URI for the <i>relativePath</i> relative to the <i>schemeSpecificPart</i>, - * hence the result is a absolute location. - * <p> - * <i>schemeSpecificPart</i>'s query, if exist is split to <i>path</i> and <i>query</i>. - * </p> - * <p> - * In case <i>path</i> is not a path ending w/ '/', it's a assumed to be a file and it's parent is being used. - * </p> - * - * @param scheme scheme of the resulting URI - * @param schemeSpecificPart may include a query, which is separated while processing (URI encoded) - * @param relativePath denotes a relative file to the baseLocation's parent directory (URI encoded) - * @param fragment the URI fragment (URI encoded) - * @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code> - * @see #encodeToURI(String) - */ - public static URI compose(final String scheme, String schemeSpecificPart, final String relativePath, final String fragment) throws URISyntaxException { - // cut off optional query in scheme-specific-part - final String query; - final int queryI = schemeSpecificPart.lastIndexOf('?'); - if( queryI >= 0 ) { - query = schemeSpecificPart.substring(queryI+1); - schemeSpecificPart = schemeSpecificPart.substring(0, queryI); - } else { - query = null; - } - if( null != relativePath ) { - if( !schemeSpecificPart.endsWith("/") ) { - schemeSpecificPart = getParentOf(schemeSpecificPart); - } - schemeSpecificPart = schemeSpecificPart + relativePath; - } - schemeSpecificPart = cleanPathString( schemeSpecificPart ); - final StringBuilder uri = new StringBuilder(); - uri.append(scheme); - uri.append(':'); - uri.append(schemeSpecificPart); - if ( null != query ) { - uri.append('?'); - uri.append(query); - } - if ( null != fragment ) { - uri.append('#'); - uri.append(fragment); - } - return new URI(uri.toString()); - } - - private static final Pattern patternSpaceRaw = Pattern.compile(" "); - private static final Pattern patternSpaceEnc = Pattern.compile("%20"); - - /** - * Escapes characters not complying w/ RFC 2396 and the {@link URI#URI(String)} ctor. - * <ul> - * <li>SPACE -> %20</li> - * </ul> - * @deprecated Useless - */ - public static String encodeToURI(final String vanilla) { - return patternSpaceRaw.matcher(vanilla).replaceAll("%20"); // Uri TODO: Uri.encode(vanilla, Uri.PATH_MIN_LEGAL); - } - - /** - * Reverses escaping of characters as performed via {@link #encodeToURI(String)}. - * <ul> - * <li>%20 -> SPACE</li> - * </ul> - * @deprecated Use {@link #decodeURIIfFilePath(URI)} - */ - public static String decodeFromURI(final String encodedUri) { - return patternSpaceEnc.matcher(encodedUri).replaceAll(" "); // Uri TODO: Uri.decode(encoded); - } - - private static final Pattern patternSingleBS = Pattern.compile("\\\\{1}"); - private static final Pattern patternSingleFS = Pattern.compile("/{1}"); - - /** - * Encodes file path characters not complying w/ RFC 2396 and the {@link URI#URI(String)} ctor. - * <p> - * Implementation processes the <code>filePath</code> if {@link File#separatorChar} <code> == '\\'</code> - * as follows: - * <ul> - * <li>backslash -> slash</li> - * <li>ensure starting with slash</li> - * </ul> - * </p> - * <p> - * Note that this method does not perform <i>space</i> encoding, - * which can be utilized via {@link #encodeToURI(String)}. - * </p> - * <p> - * Even though Oracle's JarURLStreamHandler can handle backslashes and - * erroneous URIs w/ e.g. Windows file 'syntax', other may not (Netbeans).<br> - * See Bug 857 - http://jogamp.org/bugzilla/show_bug.cgi?id=857 - * </p> - * @see #encodeToURI(String) - * @deprecated Useless - */ - public static String encodeFilePathToURI(final String filePath) { - if( File.separator.equals("\\") ) { - final String r = patternSingleBS.matcher(filePath).replaceAll("/"); - if( !r.startsWith("/") ) { - return "/" + r; - } else { - return r; - } - } - return filePath; - } - - /** - * Completes decoding uri-file path characters complying w/ RFC 2396 to native file-path. - * <p> - * Implementation decodes the space-encoding <code>path={@link #decodeFromURI(String) decodeFromURI}(uriPath)</code>. - * </p> - * <p> - * Then it processes the <code>path</code> if {@link File#separatorChar} <code> == '\\'</code> - * as follows: - * <ul> - * <li>slash -> backslash</li> - * <li>drop a starting single backslash, preserving windows UNC</li> - * </ul> - * </p> - * @param encodedUriPath URI encoded path - * @see #decodeFromURI(String) - * @deprecated Use {@link #decodeURIIfFilePath(URI)} - */ - public static String decodeURIToFilePath(final String encodedUriPath) { - final String path = patternSpaceEnc.matcher(encodedUriPath).replaceAll(" "); // Uri TODO: Uri.decode(encoded); - if( File.separator.equals("\\") ) { - final String r = patternSingleFS.matcher(path).replaceAll("\\\\"); - if( r.startsWith("\\") && !r.startsWith("\\\\") ) { // '\\\\' denotes UNC hostname, which shall not be cut-off - return r.substring(1); - } else { - return r; - } - } - return path; - } + public static final Pattern patternSpaceEnc = Pattern.compile("%20"); /** * If <code>uri</code> is a <i>file scheme</i>, @@ -890,33 +632,19 @@ public class IOUtil { * <p> * Otherwise it returns the {@link URI#toASCIIString()} encoded URI. * </p> - * - * @see #decodeFromURI(String) - * @see #decodeURIToFilePath(String) + * @deprecated Use {@link Uri#toFile()} */ - public static String decodeURIIfFilePath(final URI uri) { - if( IOUtil.FILE_SCHEME.equals( uri.getScheme() ) ) { - final String authorityS; - { - final String authority = uri.getAuthority(); - if( null == authority ) { - authorityS = ""; - } else { - authorityS = "//"+authority; - } - final String path = patternSpaceEnc.matcher(authorityS+uri.getPath()).replaceAll(" "); // Uri TODO: Uri.decode(encoded); - if( File.separator.equals("\\") ) { - final String r = patternSingleFS.matcher(path).replaceAll("\\\\"); - if( r.startsWith("\\") && !r.startsWith("\\\\") ) { // '\\\\' denotes UNC hostname, which shall not be cut-off - return r.substring(1); - } else { - return r; - } - } - return path; + public static String decodeURIIfFilePath(final java.net.URI uri) { + try { + final File file = Uri.valueOf(uri).toFile(); + if( null != file ) { + return file.getPath(); + } else { + return uri.toASCIIString(); } + } catch (final URISyntaxException e) { + throw new RuntimeException(e); } - return uri.toASCIIString(); } /** diff --git a/src/java/com/jogamp/common/util/JarUtil.java b/src/java/com/jogamp/common/util/JarUtil.java index 3fe03bf..745dd12 100644 --- a/src/java/com/jogamp/common/util/JarUtil.java +++ b/src/java/com/jogamp/common/util/JarUtil.java @@ -35,7 +35,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.JarURLConnection; -import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.net.URLConnection; @@ -46,6 +45,7 @@ import java.util.Map; import java.util.jar.JarEntry; import java.util.jar.JarFile; +import com.jogamp.common.net.Uri; import com.jogamp.common.os.NativeLibrary; import com.jogamp.common.os.Platform; @@ -111,18 +111,18 @@ public class JarUtil { * @param clazzBinName "com.jogamp.common.GlueGenVersion" * @param cl * @return true if the class is loaded from a Jar file, otherwise false. - * @see {@link #getJarURI(String, ClassLoader)} + * @see {@link #getJarUri(String, ClassLoader)} */ - public static boolean hasJarURI(final String clazzBinName, final ClassLoader cl) { + public static boolean hasJarUri(final String clazzBinName, final ClassLoader cl) { try { - return null != getJarURI(clazzBinName, cl); + return null != getJarUri(clazzBinName, cl); } catch (final Exception e) { /* ignore */ } return false; } /** * The Class's <code>"com.jogamp.common.GlueGenVersion"</code> - * URI <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"</code> + * Uri <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"</code> * will be returned. * <p> * <i>sub_protocol</i> may be "file", "http", etc.. @@ -131,108 +131,107 @@ public class JarUtil { * @param clazzBinName "com.jogamp.common.GlueGenVersion" * @param cl ClassLoader to locate the JarFile * @return "jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class" - * @throws IllegalArgumentException if the URI doesn't match the expected formatting or null arguments + * @throws IllegalArgumentException if the Uri doesn't match the expected formatting or null arguments * @throws IOException if the class's Jar file could not been found by the ClassLoader - * @throws URISyntaxException if the URI could not be translated into a RFC 2396 URI + * @throws URISyntaxException if the Uri could not be translated into a RFC 2396 Uri * @see {@link IOUtil#getClassURL(String, ClassLoader)} */ - public static URI getJarURI(final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException { + public static Uri getJarUri(final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException { if(null == clazzBinName || null == cl) { throw new IllegalArgumentException("null arguments: clazzBinName "+clazzBinName+", cl "+cl); } - final URI uri; + final Uri uri; final URL url; { url = IOUtil.getClassURL(clazzBinName, cl); final String scheme = url.getProtocol(); if( null != resolver && - !scheme.equals( IOUtil.JAR_SCHEME ) && - !scheme.equals( IOUtil.FILE_SCHEME ) && - !scheme.equals( IOUtil.HTTP_SCHEME ) && - !scheme.equals( IOUtil.HTTPS_SCHEME ) ) + !scheme.equals( Uri.JAR_SCHEME ) && + !scheme.equals( Uri.FILE_SCHEME ) && + !scheme.equals( Uri.HTTP_SCHEME ) && + !scheme.equals( Uri.HTTPS_SCHEME ) ) { final URL _url = resolver.resolve( url ); - uri = _url.toURI(); + uri = Uri.valueOf(_url); if(DEBUG) { - System.err.println("getJarURI Resolver: "+url+"\n\t-> "+_url+"\n\t-> "+uri); + System.err.println("getJarUri Resolver: "+url+"\n\t-> "+_url+"\n\t-> "+uri); } } else { - uri = url.toURI(); + uri = Uri.valueOf(url); if(DEBUG) { - System.err.println("getJarURI Default "+url+"\n\t-> "+uri); + System.err.println("getJarUri Default "+url+"\n\t-> "+uri); } } } - // test name .. - if( !uri.getScheme().equals( IOUtil.JAR_SCHEME ) ) { - throw new IllegalArgumentException("URI is not using scheme "+IOUtil.JAR_SCHEME+": <"+uri+">"); + if( !uri.scheme.equals( Uri.JAR_SCHEME ) ) { + throw new IllegalArgumentException("Uri is not using scheme "+Uri.JAR_SCHEME+": <"+uri+">"); } if(DEBUG) { - System.err.println("getJarURI res: "+clazzBinName+" -> "+url+" -> "+uri); + System.err.println("getJarUri res: "+clazzBinName+" -> "+url+" -> "+uri); } return uri; } /** - * The Class's Jar URI <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> + * The Class's Jar Uri <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> * Jar basename <code>gluegen-rt.jar</code> will be returned. * <p> * <i>sub_protocol</i> may be "file", "http", etc.. * </p> * - * @param classJarURI as retrieved w/ {@link #getJarURI(String, ClassLoader) getJarURI("com.jogamp.common.GlueGenVersion", cl).toURI()}, + * @param classJarUri as retrieved w/ {@link #getJarUri(String, ClassLoader) getJarUri("com.jogamp.common.GlueGenVersion", cl)}, * i.e. <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> * @return <code>gluegen-rt.jar</code> - * @throws IllegalArgumentException if the URI doesn't match the expected formatting or is null + * @throws IllegalArgumentException if the Uri doesn't match the expected formatting or is null * @see {@link IOUtil#getClassURL(String, ClassLoader)} */ - public static String getJarBasename(final URI classJarURI) throws IllegalArgumentException { - if(null == classJarURI) { - throw new IllegalArgumentException("URI is null"); + public static Uri.Encoded getJarBasename(final Uri classJarUri) throws IllegalArgumentException { + if(null == classJarUri) { + throw new IllegalArgumentException("Uri is null"); } - if( !classJarURI.getScheme().equals(IOUtil.JAR_SCHEME) ) { - throw new IllegalArgumentException("URI is not using scheme "+IOUtil.JAR_SCHEME+": <"+classJarURI+">"); + if( !classJarUri.scheme.equals(Uri.JAR_SCHEME) ) { + throw new IllegalArgumentException("Uri is not using scheme "+Uri.JAR_SCHEME+": <"+classJarUri+">"); } - String uriS = classJarURI.getSchemeSpecificPart(); + Uri.Encoded ssp = classJarUri.schemeSpecificPart; // from // file:/some/path/gluegen-rt.jar!/com/jogamp/common/util/cache/TempJarCache.class // to // file:/some/path/gluegen-rt.jar - int idx = uriS.lastIndexOf(IOUtil.JAR_SCHEME_SEPARATOR); + int idx = ssp.lastIndexOf(Uri.JAR_SCHEME_SEPARATOR); if (0 <= idx) { - uriS = uriS.substring(0, idx); // exclude '!/' + ssp = ssp.substring(0, idx); // exclude '!/' } else { - throw new IllegalArgumentException("URI does not contain jar uri terminator '!', in <"+classJarURI+">"); + throw new IllegalArgumentException("Uri does not contain jar uri terminator '!', in <"+classJarUri+">"); } // from // file:/some/path/gluegen-rt.jar // to // gluegen-rt.jar - idx = uriS.lastIndexOf('/'); + idx = ssp.lastIndexOf('/'); if(0 > idx) { // no abs-path, check for protocol terminator ':' - idx = uriS.lastIndexOf(':'); + idx = ssp.lastIndexOf(':'); if(0 > idx) { - throw new IllegalArgumentException("URI does not contain protocol terminator ':', in <"+classJarURI+">"); + throw new IllegalArgumentException("Uri does not contain protocol terminator ':', in <"+classJarUri+">"); } } - uriS = uriS.substring(idx+1); // just the jar name + ssp = ssp.substring(idx+1); // just the jar name - if(0 >= uriS.lastIndexOf(".jar")) { - throw new IllegalArgumentException("No Jar name in <"+classJarURI+">"); + if(0 >= ssp.lastIndexOf(".jar")) { + throw new IllegalArgumentException("No Jar name in <"+classJarUri+">"); } if(DEBUG) { - System.err.println("getJarName res: "+uriS); + System.err.println("getJarName res: "+ssp); } - return uriS; + return ssp; } /** * The Class's <code>com.jogamp.common.GlueGenVersion</code> - * URI <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> + * Uri <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> * Jar basename <code>gluegen-rt.jar</code> will be returned. * <p> * <i>sub_protocol</i> may be "file", "http", etc.. @@ -241,119 +240,54 @@ public class JarUtil { * @param clazzBinName <code>com.jogamp.common.GlueGenVersion</code> * @param cl * @return <code>gluegen-rt.jar</code> - * @throws IllegalArgumentException if the URI doesn't match the expected formatting + * @throws IllegalArgumentException if the Uri doesn't match the expected formatting * @throws IOException if the class's Jar file could not been found by the ClassLoader. - * @throws URISyntaxException if the URI could not be translated into a RFC 2396 URI + * @throws URISyntaxException if the Uri could not be translated into a RFC 2396 Uri * @see {@link IOUtil#getClassURL(String, ClassLoader)} */ - public static String getJarBasename(final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException { - return getJarBasename( getJarURI(clazzBinName, cl) ); + public static Uri.Encoded getJarBasename(final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException { + return getJarBasename( getJarUri(clazzBinName, cl) ); } /** - * The Class's Jar URI <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> - * Jar file's sub URI <code><i>sub_protocol</i>:/some/path/gluegen-rt.jar</code> will be returned. - * <p> - * <i>sub_protocol</i> may be "file", "http", etc.. - * </p> - * - * @param classJarURI as retrieved w/ {@link #getJarURI(String, ClassLoader) getJarURI("com.jogamp.common.GlueGenVersion", cl).toURI()}, - * i.e. <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> - * @return <code><i>sub_protocol</i>:/some/path/gluegen-rt.jar</code> - * @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 - * @see {@link IOUtil#getClassURL(String, ClassLoader)} - */ - public static URI getJarSubURI(final URI classJarURI) throws IllegalArgumentException, URISyntaxException { - 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+">"); - } - - // from - // file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class - // to - // file:/some/path/gluegen-rt.jar - final String uriSSP = classJarURI.getRawSchemeSpecificPart(); - final int idx = uriSSP.lastIndexOf(IOUtil.JAR_SCHEME_SEPARATOR); - final String uriSSPJar; - if (0 <= idx) { - uriSSPJar = uriSSP.substring(0, idx); // exclude '!/' - } else { - throw new IllegalArgumentException("JAR URI does not contain jar uri terminator '!', uri <"+classJarURI+">"); - } - if(0 >= uriSSPJar.lastIndexOf(".jar")) { - throw new IllegalArgumentException("No Jar name in <"+classJarURI+">"); - } - if(DEBUG) { - System.err.println("getJarSubURI res: "+classJarURI+" -> "+uriSSP+" -> "+uriSSPJar); - } - return new URI(uriSSPJar); - } - - /** - * The Class's Jar URI <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> + * The Class's Jar Uri <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> * Jar file's entry <code>/com/jogamp/common/GlueGenVersion.class</code> will be returned. * - * @param classJarURI as retrieved w/ {@link #getJarURI(String, ClassLoader) getJarURI("com.jogamp.common.GlueGenVersion", cl).toURI()}, + * @param classJarUri as retrieved w/ {@link #getJarUri(String, ClassLoader) getJarUri("com.jogamp.common.GlueGenVersion", cl)}, * i.e. <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> * @return <code>/com/jogamp/common/GlueGenVersion.class</code> * @see {@link IOUtil#getClassURL(String, ClassLoader)} - * @deprecated Useless */ - public static String getJarEntry(final URI classJarURI) { - if(null == classJarURI) { - throw new IllegalArgumentException("URI is null"); + public static Uri.Encoded getJarEntry(final 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+">"); + if( !classJarUri.scheme.equals(Uri.JAR_SCHEME) ) { + throw new IllegalArgumentException("Uri is not a using scheme "+Uri.JAR_SCHEME+": <"+classJarUri+">"); } - final String uriSSP = classJarURI.getSchemeSpecificPart(); - // Uri TODO ? final String uriSSP = classJarURI.getRawSchemeSpecificPart(); + final Uri.Encoded uriSSP = classJarUri.schemeSpecificPart; // from // file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class // to // /com/jogamp/common/GlueGenVersion.class - final int idx = uriSSP.lastIndexOf(IOUtil.JAR_SCHEME_SEPARATOR); + final int idx = uriSSP.lastIndexOf(Uri.JAR_SCHEME_SEPARATOR); if (0 <= idx) { - final String res = uriSSP.substring(idx+1); // right of '!' + final Uri.Encoded res = uriSSP.substring(idx+1); // right of '!' // Uri TODO ? final String res = Uri.decode(uriSSP.substring(idx+1)); // right of '!' if(DEBUG) { - System.err.println("getJarEntry res: "+classJarURI+" -> "+uriSSP+" -> "+idx+" -> "+res); + System.err.println("getJarEntry res: "+classJarUri+" -> "+uriSSP+" -> "+idx+" -> "+res); } return res; } else { - throw new IllegalArgumentException("JAR URI does not contain jar uri terminator '!', uri <"+classJarURI+">"); + throw new IllegalArgumentException("JAR Uri does not contain jar uri terminator '!', uri <"+classJarUri+">"); } } /** - * The Class's <code>com.jogamp.common.GlueGenVersion</code> - * URI <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class</code> - * Jar file's sub URI <code><i>sub_protocol</i>:/some/path/gluegen-rt.jar</code> will be returned. - * <p> - * <i>sub_protocol</i> may be "file", "http", etc.. - * </p> - * - * @param clazzBinName <code>com.jogamp.common.GlueGenVersion</code> - * @param cl - * @return <code><i>sub_protocol</i>:/some/path/gluegen-rt.jar</code> - * @throws IllegalArgumentException if the URI doesn't match the expected formatting - * @throws IOException if the class's Jar file could not been found by the ClassLoader - * @throws URISyntaxException if the URI could not be translated into a RFC 2396 URI - * @see {@link IOUtil#getClassURL(String, ClassLoader)} - */ - public static URI getJarSubURI(final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException { - return getJarSubURI( getJarURI(clazzBinName, cl) ); - } - - /** * The Class's <code>"com.jogamp.common.GlueGenVersion"</code> - * URI <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"</code> - * Jar file URI <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/</code> will be returned. + * Uri <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class"</code> + * Jar file Uri <code>jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/</code> will be returned. * <p> * <i>sub_protocol</i> may be "file", "http", etc.. * </p> @@ -361,34 +295,35 @@ public class JarUtil { * @param clazzBinName "com.jogamp.common.GlueGenVersion" * @param cl * @return "jar:<i>sub_protocol</i>:/some/path/gluegen-rt.jar!/" - * @throws IllegalArgumentException if the URI doesn't match the expected formatting or null arguments + * @throws IllegalArgumentException if the Uri doesn't match the expected formatting or null arguments * @throws IOException if the class's Jar file could not been found by the ClassLoader - * @throws URISyntaxException if the URI could not be translated into a RFC 2396 URI + * @throws URISyntaxException if the Uri could not be translated into a RFC 2396 Uri * @see {@link IOUtil#getClassURL(String, ClassLoader)} */ - public static URI getJarFileURI(final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException { + public static Uri getJarFileUri(final String clazzBinName, final ClassLoader cl) throws IllegalArgumentException, IOException, URISyntaxException { if(null == clazzBinName || null == cl) { throw new IllegalArgumentException("null arguments: clazzBinName "+clazzBinName+", cl "+cl); } - final URI uri = new URI(IOUtil.JAR_SCHEME+IOUtil.SCHEME_SEPARATOR+getJarSubURI(clazzBinName, cl).toString()+"!/"); + final Uri jarSubUri = getJarUri(clazzBinName, cl).getContainedUri(); + final Uri uri = Uri.cast(Uri.JAR_SCHEME+Uri.SCHEME_SEPARATOR+jarSubUri.toString()+"!/"); if(DEBUG) { - System.err.println("getJarFileURI res: "+uri); + System.err.println("getJarFileUri res: "+uri); } return uri; } /** * @param baseUri file:/some/path/ - * @param jarFileName gluegen-rt.jar (URI encoded) + * @param jarFileName gluegen-rt.jar (Uri encoded) * @return jar:file:/some/path/gluegen-rt.jar!/ * @throws URISyntaxException * @throws IllegalArgumentException null arguments */ - public static URI getJarFileURI(final URI baseUri, final String jarFileName) throws IllegalArgumentException, URISyntaxException { + public static Uri getJarFileUri(final Uri baseUri, final Uri.Encoded jarFileName) throws IllegalArgumentException, URISyntaxException { if(null == baseUri || null == jarFileName) { - throw new IllegalArgumentException("null arguments: baseURI "+baseUri+", jarFileName "+jarFileName); + throw new IllegalArgumentException("null arguments: baseUri "+baseUri+", jarFileName "+jarFileName); } - return new URI(IOUtil.JAR_SCHEME+IOUtil.SCHEME_SEPARATOR+baseUri.toString()+jarFileName+"!/"); + return Uri.cast(Uri.JAR_SCHEME+Uri.SCHEME_SEPARATOR+baseUri.toString()+jarFileName+"!/"); } /** @@ -397,38 +332,38 @@ public class JarUtil { * @throws IllegalArgumentException null arguments * @throws URISyntaxException */ - public static URI getJarFileURI(final URI jarSubUri) throws IllegalArgumentException, URISyntaxException { + public static Uri getJarFileUri(final Uri jarSubUri) throws IllegalArgumentException, URISyntaxException { if(null == jarSubUri) { - throw new IllegalArgumentException("jarSubURI is null"); + throw new IllegalArgumentException("jarSubUri is null"); } - return new URI(IOUtil.JAR_SCHEME+IOUtil.SCHEME_SEPARATOR+jarSubUri.toString()+"!/"); + return Uri.cast(Uri.JAR_SCHEME+Uri.SCHEME_SEPARATOR+jarSubUri.toString()+"!/"); } /** - * @param jarSubUriS file:/some/path/gluegen-rt.jar (URI encoded) + * @param jarSubUriS file:/some/path/gluegen-rt.jar (Uri encoded) * @return jar:file:/some/path/gluegen-rt.jar!/ * @throws IllegalArgumentException null arguments * @throws URISyntaxException */ - public static URI getJarFileURI(final String jarSubUriS) throws IllegalArgumentException, URISyntaxException { + public static Uri getJarFileUri(final Uri.Encoded jarSubUriS) throws IllegalArgumentException, URISyntaxException { if(null == jarSubUriS) { - throw new IllegalArgumentException("jarSubURIS is null"); + throw new IllegalArgumentException("jarSubUriS is null"); } - return new URI(IOUtil.JAR_SCHEME+IOUtil.SCHEME_SEPARATOR+jarSubUriS+"!/"); + return Uri.cast(Uri.JAR_SCHEME+Uri.SCHEME_SEPARATOR+jarSubUriS+"!/"); } /** - * @param jarFileURI jar:file:/some/path/gluegen-rt.jar!/ + * @param jarFileUri jar:file:/some/path/gluegen-rt.jar!/ * @param jarEntry com/jogamp/common/GlueGenVersion.class * @return jar:file:/some/path/gluegen-rt.jar!/com/jogamp/common/GlueGenVersion.class * @throws IllegalArgumentException null arguments * @throws URISyntaxException */ - public static URI getJarEntryURI(final URI jarFileURI, final String jarEntry) throws IllegalArgumentException, URISyntaxException { + public static Uri getJarEntryUri(final Uri jarFileUri, final Uri.Encoded jarEntry) throws IllegalArgumentException, URISyntaxException { if(null == jarEntry) { throw new IllegalArgumentException("jarEntry is null"); } - return new URI(jarFileURI.toString()+jarEntry); + return Uri.cast(jarFileUri.toString()+jarEntry); } /** @@ -437,28 +372,28 @@ public class JarUtil { * @return JarFile containing the named class within the given ClassLoader * @throws IOException if the class's Jar file could not been found by the ClassLoader * @throws IllegalArgumentException null arguments - * @throws URISyntaxException if the URI could not be translated into a RFC 2396 URI - * @see {@link #getJarFileURI(String, ClassLoader)} + * @throws URISyntaxException if the Uri could not be translated into a RFC 2396 Uri + * @see {@link #getJarFileUri(String, ClassLoader)} */ public static JarFile getJarFile(final String clazzBinName, final ClassLoader cl) throws IOException, IllegalArgumentException, URISyntaxException { - return getJarFile( getJarFileURI(clazzBinName, cl) ); + return getJarFile( getJarFileUri(clazzBinName, cl) ); } /** - * @param jarFileURI jar:file:/some/path/gluegen-rt.jar!/ - * @return JarFile as named by URI within the given ClassLoader + * @param jarFileUri jar:file:/some/path/gluegen-rt.jar!/ + * @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(final URI jarFileURI) throws IOException, IllegalArgumentException, URISyntaxException { - if(null == jarFileURI) { - throw new IllegalArgumentException("null jarFileURI"); + public static JarFile getJarFile(final Uri jarFileUri) throws IOException, IllegalArgumentException, URISyntaxException { + if(null == jarFileUri) { + throw new IllegalArgumentException("null jarFileUri"); } if(DEBUG) { - System.err.println("getJarFile.0: "+jarFileURI.toString()); + System.err.println("getJarFile.0: "+jarFileUri.toString()); } - final URL jarFileURL = jarFileURI.toURL(); + final URL jarFileURL = jarFileUri.toURL(); if(DEBUG) { System.err.println("getJarFile.1: "+jarFileURL.toString()); } @@ -478,8 +413,22 @@ public class JarUtil { } /** - * Locates the {@link JarUtil#getJarFileURI(URI) Jar file URI} of a given resource - * relative to a given class's Jar's URI. + * See {@link #getRelativeOf(Class, com.jogamp.common.net.Uri.Encoded, com.jogamp.common.net.Uri.Encoded)}. + * @param classFromJavaJar URI encoded! + * @param cutOffInclSubDir URI encoded! + * @param relResPath URI encoded! + * @return + * @throws IllegalArgumentException + * @throws IOException + * @throws URISyntaxException + * @deprecated Use {@link #getRelativeOf(Class, com.jogamp.common.net.Uri.Encoded, com.jogamp.common.net.Uri.Encoded)}. + */ + public static java.net.URI getRelativeOf(final Class<?> classFromJavaJar, final String cutOffInclSubDir, final String relResPath) throws IllegalArgumentException, IOException, URISyntaxException { + return getRelativeOf(classFromJavaJar, Uri.Encoded.cast(cutOffInclSubDir), Uri.Encoded.cast(relResPath)).toURI(); + } + /** + * Locates the {@link JarUtil#getJarFileUri(Uri) Jar file Uri} of a given resource + * relative to a given class's Jar's Uri. * <pre> * class's jar url path + cutOffInclSubDir + relResPath, * </pre> @@ -500,47 +449,47 @@ public class JarUtil { * * TODO: Enhance documentation! * - * @param classFromJavaJar Used to get the root URI for the class's Jar URI. + * @param classFromJavaJar Used to get the root Uri for the class's Jar Uri. * @param cutOffInclSubDir The <i>cut off</i> included sub-directory prepending the relative resource path. - * If the root URI includes cutOffInclSubDir, it is no more added to the result. - * @param relResPath The relative resource path. (URI encoded) - * @return The resulting resource URI, which is not tested. + * If the root Uri includes cutOffInclSubDir, it is no more added to the result. + * @param relResPath The relative resource path. (Uri encoded) + * @return The resulting resource Uri, which is not tested. * @throws IllegalArgumentException * @throws IOException * @throws URISyntaxException */ - public static URI getRelativeOf(final Class<?> classFromJavaJar, final String cutOffInclSubDir, final String relResPath) throws IllegalArgumentException, IOException, URISyntaxException { + public static Uri getRelativeOf(final Class<?> classFromJavaJar, final Uri.Encoded cutOffInclSubDir, final Uri.Encoded relResPath) throws IllegalArgumentException, IOException, URISyntaxException { final ClassLoader cl = classFromJavaJar.getClassLoader(); - final URI classJarURI = JarUtil.getJarURI(classFromJavaJar.getName(), cl); + final Uri classJarUri = JarUtil.getJarUri(classFromJavaJar.getName(), cl); if( DEBUG ) { - System.err.println("JarUtil.getRelativeOf: "+"(classFromJavaJar "+classFromJavaJar+", classJarURI "+classJarURI+ + System.err.println("JarUtil.getRelativeOf: "+"(classFromJavaJar "+classFromJavaJar+", classJarUri "+classJarUri+ ", cutOffInclSubDir "+cutOffInclSubDir+", relResPath "+relResPath+"): "); } - final URI jarSubURI = JarUtil.getJarSubURI( classJarURI ); - if(null == jarSubURI) { - throw new IllegalArgumentException("JarSubURI is null of: "+classJarURI); + final Uri jarSubUri = classJarUri.getContainedUri(); + if(null == jarSubUri) { + throw new IllegalArgumentException("JarSubUri is null of: "+classJarUri); } - final String jarUriRoot_s = IOUtil.getURIDirname( jarSubURI.toString() ); + final Uri.Encoded jarUriRoot = jarSubUri.getDirectory().getEncoded(); if( DEBUG ) { - System.err.println("JarUtil.getRelativeOf: "+"uri "+jarSubURI.toString()+" -> "+jarUriRoot_s); + System.err.println("JarUtil.getRelativeOf: "+"uri "+jarSubUri.toString()+" -> "+jarUriRoot); } - final String resUri_s; - if( jarUriRoot_s.endsWith(cutOffInclSubDir) ) { - resUri_s = jarUriRoot_s+relResPath; + final Uri.Encoded resUri; + if( jarUriRoot.endsWith(cutOffInclSubDir.get()) ) { + resUri = jarUriRoot.concat(relResPath); } else { - resUri_s = jarUriRoot_s+cutOffInclSubDir+relResPath; + resUri = jarUriRoot.concat(cutOffInclSubDir).concat(relResPath); } if( DEBUG ) { - System.err.println("JarUtil.getRelativeOf: "+"... -> "+resUri_s); + System.err.println("JarUtil.getRelativeOf: "+"... -> "+resUri); } - final URI resURI = JarUtil.getJarFileURI(resUri_s); + final Uri resJarUri = JarUtil.getJarFileUri(resUri); if( DEBUG ) { - System.err.println("JarUtil.getRelativeOf: "+"fin "+resURI); + System.err.println("JarUtil.getRelativeOf: "+"fin "+resJarUri); } - return resURI; + return resJarUri; } /** diff --git a/src/java/com/jogamp/common/util/cache/TempJarCache.java b/src/java/com/jogamp/common/util/cache/TempJarCache.java index 1b322d7..05d92e1 100644 --- a/src/java/com/jogamp/common/util/cache/TempJarCache.java +++ b/src/java/com/jogamp/common/util/cache/TempJarCache.java @@ -29,7 +29,6 @@ package com.jogamp.common.util.cache; import java.io.File; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; import java.security.cert.Certificate; import java.util.HashMap; @@ -38,8 +37,8 @@ import java.util.jar.JarFile; import jogamp.common.Debug; +import com.jogamp.common.net.Uri; import com.jogamp.common.os.NativeLibrary; -import com.jogamp.common.util.IOUtil; import com.jogamp.common.util.JarUtil; import com.jogamp.common.util.SecurityUtil; @@ -68,9 +67,9 @@ public class TempJarCache { } // Set of jar files added - private static Map<URI, LoadState> nativeLibJars; - private static Map<URI, LoadState> classFileJars; - private static Map<URI, LoadState> resourceFileJars; + private static Map<Uri, LoadState> nativeLibJars; + private static Map<Uri, LoadState> classFileJars; + private static Map<Uri, LoadState> resourceFileJars; private static TempFileCache tmpFileCache; @@ -96,9 +95,9 @@ public class TempJarCache { if(!staticInitError) { // Initialize the collections of resources nativeLibMap = new HashMap<String, String>(); - nativeLibJars = new HashMap<URI, LoadState>(); - classFileJars = new HashMap<URI, LoadState>(); - resourceFileJars = new HashMap<URI, LoadState>(); + nativeLibJars = new HashMap<Uri, LoadState>(); + classFileJars = new HashMap<Uri, LoadState>(); + resourceFileJars = new HashMap<Uri, LoadState>(); } if(DEBUG) { System.err.println("TempJarCache.initSingleton(): ok "+(false==staticInitError)+", "+ tmpFileCache.getTempDir()); @@ -182,62 +181,62 @@ public class TempJarCache { return tmpFileCache; } - public synchronized static boolean checkNativeLibs(final URI jarURI, final LoadState exp) throws IOException { + public synchronized static boolean checkNativeLibs(final Uri jarUri, final LoadState exp) throws IOException { checkInitialized(); - if(null == jarURI) { - throw new IllegalArgumentException("jarURI is null"); + if(null == jarUri) { + throw new IllegalArgumentException("jarUri is null"); } - return testLoadState(nativeLibJars.get(jarURI), exp); + return testLoadState(nativeLibJars.get(jarUri), exp); } - public synchronized static boolean checkClasses(final URI jarURI, final LoadState exp) throws IOException { + public synchronized static boolean checkClasses(final Uri jarUri, final LoadState exp) throws IOException { checkInitialized(); - if(null == jarURI) { - throw new IllegalArgumentException("jarURI is null"); + if(null == jarUri) { + throw new IllegalArgumentException("jarUri is null"); } - return testLoadState(classFileJars.get(jarURI), exp); + return testLoadState(classFileJars.get(jarUri), exp); } - public synchronized static boolean checkResources(final URI jarURI, final LoadState exp) throws IOException { + public synchronized static boolean checkResources(final Uri jarUri, final LoadState exp) throws IOException { checkInitialized(); - if(null == jarURI) { - throw new IllegalArgumentException("jarURI is null"); + if(null == jarUri) { + throw new IllegalArgumentException("jarUri is null"); } - return testLoadState(resourceFileJars.get(jarURI), exp); + return testLoadState(resourceFileJars.get(jarUri), exp); } /** * Adds native libraries, if not yet added. * * @param certClass if class is certified, the JarFile entries needs to have the same certificate - * @param jarURI + * @param jarUri * @param nativeLibraryPath if not null, only extracts native libraries within this path. - * @return true if native libraries were added or previously loaded from given jarURI, otherwise false - * @throws IOException if the <code>jarURI</code> could not be loaded or a previous load attempt failed + * @return true if native libraries were added or previously loaded from given jarUri, otherwise false + * @throws IOException if the <code>jarUri</code> could not be loaded or a previous load attempt failed * @throws SecurityException * @throws URISyntaxException * @throws IllegalArgumentException */ - public synchronized static final boolean addNativeLibs(final Class<?> certClass, final URI jarURI, final String nativeLibraryPath) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { + public synchronized static final boolean addNativeLibs(final Class<?> certClass, final Uri jarUri, final String nativeLibraryPath) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { checkInitialized(); - final LoadState nativeLibJarsLS = nativeLibJars.get(jarURI); + final LoadState nativeLibJarsLS = nativeLibJars.get(jarUri); if( !testLoadState(nativeLibJarsLS, LoadState.LOOKED_UP) ) { - nativeLibJars.put(jarURI, LoadState.LOOKED_UP); - final JarFile jarFile = JarUtil.getJarFile(jarURI); + nativeLibJars.put(jarUri, LoadState.LOOKED_UP); + final JarFile jarFile = JarUtil.getJarFile(jarUri); if(DEBUG) { - System.err.println("TempJarCache: addNativeLibs: "+jarURI+": nativeJar "+jarFile.getName()+" (NEW)"); + System.err.println("TempJarCache: addNativeLibs: "+jarUri+": nativeJar "+jarFile.getName()+" (NEW)"); } validateCertificates(certClass, jarFile); final int num = JarUtil.extract(tmpFileCache.getTempDir(), nativeLibMap, jarFile, nativeLibraryPath, true, false, false); - nativeLibJars.put(jarURI, LoadState.LOADED); + nativeLibJars.put(jarUri, LoadState.LOADED); return num > 0; } else if( testLoadState(nativeLibJarsLS, LoadState.LOADED) ) { if(DEBUG) { - System.err.println("TempJarCache: addNativeLibs: "+jarURI+": nativeJar "+jarURI+" (REUSE)"); + System.err.println("TempJarCache: addNativeLibs: "+jarUri+": nativeJar "+jarUri+" (REUSE)"); } return true; } - throw new IOException("TempJarCache: addNativeLibs: "+jarURI+", previous load attempt failed"); + throw new IOException("TempJarCache: addNativeLibs: "+jarUri+", previous load attempt failed"); } /** @@ -247,56 +246,69 @@ public class TempJarCache { * needs Classloader.defineClass(..) access, ie. own derivation - will do when needed .. * * @param certClass if class is certified, the JarFile entries needs to have the same certificate - * @param jarURI - * @throws IOException if the <code>jarURI</code> could not be loaded or a previous load attempt failed + * @param jarUri + * @throws IOException if the <code>jarUri</code> could not be loaded or a previous load attempt failed * @throws SecurityException * @throws URISyntaxException * @throws IllegalArgumentException */ - public synchronized static final void addClasses(final Class<?> certClass, final URI jarURI) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { + public synchronized static final void addClasses(final Class<?> certClass, final Uri jarUri) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { checkInitialized(); - final LoadState classFileJarsLS = classFileJars.get(jarURI); + final LoadState classFileJarsLS = classFileJars.get(jarUri); if( !testLoadState(classFileJarsLS, LoadState.LOOKED_UP) ) { - classFileJars.put(jarURI, LoadState.LOOKED_UP); - final JarFile jarFile = JarUtil.getJarFile(jarURI); + classFileJars.put(jarUri, LoadState.LOOKED_UP); + final JarFile jarFile = JarUtil.getJarFile(jarUri); if(DEBUG) { - System.err.println("TempJarCache: addClasses: "+jarURI+": nativeJar "+jarFile.getName()); + System.err.println("TempJarCache: addClasses: "+jarUri+": nativeJar "+jarFile.getName()); } validateCertificates(certClass, jarFile); JarUtil.extract(tmpFileCache.getTempDir(), null, jarFile, null /* nativeLibraryPath */, false, true, false); - classFileJars.put(jarURI, LoadState.LOADED); + classFileJars.put(jarUri, LoadState.LOADED); } else if( !testLoadState(classFileJarsLS, LoadState.LOADED) ) { - throw new IOException("TempJarCache: addClasses: "+jarURI+", previous load attempt failed"); + throw new IOException("TempJarCache: addClasses: "+jarUri+", previous load attempt failed"); } } /** + * See {@link #addResources(Class, Uri)} + * @param certClass + * @param jarURI + * @throws IOException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws URISyntaxException + * @deprecated Use {@link #addResources(Class, Uri)} + */ + public synchronized static final void addResources(final Class<?> certClass, final java.net.URI jarURI) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { + addResources(certClass, Uri.valueOf(jarURI)); + } + /** * Adds native resources, if not yet added. * * @param certClass if class is certified, the JarFile entries needs to have the same certificate - * @param jarURI + * @param jarUri * @return - * @throws IOException if the <code>jarURI</code> could not be loaded or a previous load attempt failed + * @throws IOException if the <code>jarUri</code> could not be loaded or a previous load attempt failed * @throws SecurityException * @throws URISyntaxException * @throws IllegalArgumentException */ - public synchronized static final void addResources(final Class<?> certClass, final URI jarURI) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { + public synchronized static final void addResources(final Class<?> certClass, final Uri jarUri) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { checkInitialized(); - final LoadState resourceFileJarsLS = resourceFileJars.get(jarURI); + final LoadState resourceFileJarsLS = resourceFileJars.get(jarUri); if( !testLoadState(resourceFileJarsLS, LoadState.LOOKED_UP) ) { - resourceFileJars.put(jarURI, LoadState.LOOKED_UP); - final JarFile jarFile = JarUtil.getJarFile(jarURI); + resourceFileJars.put(jarUri, LoadState.LOOKED_UP); + final JarFile jarFile = JarUtil.getJarFile(jarUri); if(DEBUG) { - System.err.println("TempJarCache: addResources: "+jarURI+": nativeJar "+jarFile.getName()); + System.err.println("TempJarCache: addResources: "+jarUri+": nativeJar "+jarFile.getName()); } validateCertificates(certClass, jarFile); JarUtil.extract(tmpFileCache.getTempDir(), null, jarFile, null /* nativeLibraryPath */, false, false, true); - resourceFileJars.put(jarURI, LoadState.LOADED); + resourceFileJars.put(jarUri, LoadState.LOADED); } else if( !testLoadState(resourceFileJarsLS, LoadState.LOADED) ) { - throw new IOException("TempJarCache: addResources: "+jarURI+", previous load attempt failed"); + throw new IOException("TempJarCache: addResources: "+jarUri+", previous load attempt failed"); } } @@ -308,20 +320,20 @@ public class TempJarCache { * needs Classloader.defineClass(..) access, ie. own derivation - will do when needed .. * * @param certClass if class is certified, the JarFile entries needs to have the same certificate - * @param jarURI - * @throws IOException if the <code>jarURI</code> could not be loaded or a previous load attempt failed + * @param jarUri + * @throws IOException if the <code>jarUri</code> could not be loaded or a previous load attempt failed * @throws SecurityException * @throws URISyntaxException * @throws IllegalArgumentException */ - public synchronized static final void addAll(final Class<?> certClass, final URI jarURI) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { + public synchronized static final void addAll(final Class<?> certClass, final Uri jarUri) throws IOException, SecurityException, IllegalArgumentException, URISyntaxException { checkInitialized(); - if(null == jarURI) { - throw new IllegalArgumentException("jarURI is null"); + if(null == jarUri) { + throw new IllegalArgumentException("jarUri is null"); } - final LoadState nativeLibJarsLS = nativeLibJars.get(jarURI); - final LoadState classFileJarsLS = classFileJars.get(jarURI); - final LoadState resourceFileJarsLS = resourceFileJars.get(jarURI); + final LoadState nativeLibJarsLS = nativeLibJars.get(jarUri); + final LoadState classFileJarsLS = classFileJars.get(jarUri); + final LoadState resourceFileJarsLS = resourceFileJars.get(jarUri); if( !testLoadState(nativeLibJarsLS, LoadState.LOOKED_UP) || !testLoadState(classFileJarsLS, LoadState.LOOKED_UP) || !testLoadState(resourceFileJarsLS, LoadState.LOOKED_UP) ) { @@ -332,18 +344,18 @@ public class TempJarCache { // mark looked-up (those who are not loaded) if(extractNativeLibraries) { - nativeLibJars.put(jarURI, LoadState.LOOKED_UP); + nativeLibJars.put(jarUri, LoadState.LOOKED_UP); } if(extractClassFiles) { - classFileJars.put(jarURI, LoadState.LOOKED_UP); + classFileJars.put(jarUri, LoadState.LOOKED_UP); } if(extractOtherFiles) { - resourceFileJars.put(jarURI, LoadState.LOOKED_UP); + resourceFileJars.put(jarUri, LoadState.LOOKED_UP); } - final JarFile jarFile = JarUtil.getJarFile(jarURI); + final JarFile jarFile = JarUtil.getJarFile(jarUri); if(DEBUG) { - System.err.println("TempJarCache: addAll: "+jarURI+": nativeJar "+jarFile.getName()); + System.err.println("TempJarCache: addAll: "+jarUri+": nativeJar "+jarFile.getName()); } validateCertificates(certClass, jarFile); JarUtil.extract(tmpFileCache.getTempDir(), nativeLibMap, jarFile, @@ -351,18 +363,18 @@ public class TempJarCache { // mark loaded (those were just loaded) if(extractNativeLibraries) { - nativeLibJars.put(jarURI, LoadState.LOADED); + nativeLibJars.put(jarUri, LoadState.LOADED); } if(extractClassFiles) { - classFileJars.put(jarURI, LoadState.LOADED); + classFileJars.put(jarUri, LoadState.LOADED); } if(extractOtherFiles) { - resourceFileJars.put(jarURI, LoadState.LOADED); + resourceFileJars.put(jarUri, LoadState.LOADED); } } else if( !testLoadState(nativeLibJarsLS, LoadState.LOADED) || !testLoadState(classFileJarsLS, LoadState.LOADED) || !testLoadState(resourceFileJarsLS, LoadState.LOADED) ) { - throw new IOException("TempJarCache: addAll: "+jarURI+", previous load attempt failed"); + throw new IOException("TempJarCache: addAll: "+jarUri+", previous load attempt failed"); } } @@ -407,12 +419,20 @@ public class TempJarCache { return null; } + /** + * See {@link #getResourceUri(String)} + * @deprecated Use {@link #getResourceUri(String)} + */ + public synchronized static final java.net.URI getResource(final String name) throws URISyntaxException { + return getResourceUri(name).toURI(); + } + /** Similar to {@link ClassLoader#getResource(String)}. */ - public synchronized static final URI getResource(final String name) throws URISyntaxException { + public synchronized static final Uri getResourceUri(final String name) throws URISyntaxException { checkInitialized(); final File f = new File(tmpFileCache.getTempDir(), name); if(f.exists()) { - return IOUtil.toURISimple(f); + return Uri.valueOf(f); } return null; } |