From ca7a1864a1624539048809d0a1c491f57c145d15 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 1 Oct 2013 23:03:18 +0200 Subject: IOUtil/JarUtil: Add more detail debug information for URI transformation; IOUtil.toURL(..) handle exception at 'new File(uri)' --- src/java/com/jogamp/common/util/IOUtil.java | 40 ++++++++++++++++++++-------- src/java/com/jogamp/common/util/JarUtil.java | 19 ++++++++----- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 6b9eef8..5918213 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -513,22 +513,40 @@ public class IOUtil { * @throws URISyntaxException */ public static URL toURL(URI uri) throws IOException, IllegalArgumentException, URISyntaxException { - final URL url; + URL url = null; final String uriSchema = uri.getScheme(); final boolean isJAR = IOUtil.JAR_SCHEME.equals(uriSchema); - final URI specificURI = isJAR ? JarUtil.getJarSubURI(uri) : uri; + final URI specificURI = isJAR ? JarUtil.getJarSubURI(uri) : uri; + int mode = 0; if( IOUtil.FILE_SCHEME.equals( specificURI.getScheme() ) ) { - final File f = new File(specificURI); - if( specificURI == uri ) { - url = new URL(IOUtil.FILE_SCHEME+IOUtil.SCHEME_SEPARATOR+f.getPath()); - // url = f.toURI().toURL(); // Doesn't work, since it uses encoded path! - } else { - final String post = isJAR ? IOUtil.JAR_SCHEME_SEPARATOR + JarUtil.getJarEntry(uri) : ""; - final String urlS = uriSchema+IOUtil.SCHEME_SEPARATOR+IOUtil.FILE_SCHEME+IOUtil.SCHEME_SEPARATOR+f.getPath()+post; - url = new URL(urlS); + File f; + try { + f = new File(specificURI); + } catch( IllegalArgumentException iae) { + if( DEBUG ) { + System.out.println("toURL: "+uri+" -> File("+specificURI+") failed: "+iae.getMessage()); + } + f = null; } - } else { + if( null != f ) { + if( specificURI == uri ) { + url = new URL(IOUtil.FILE_SCHEME+IOUtil.SCHEME_SEPARATOR+f.getPath()); + // url = f.toURI().toURL(); // Doesn't work, since it uses encoded path! + mode = 1; + } else { + final String post = isJAR ? IOUtil.JAR_SCHEME_SEPARATOR + JarUtil.getJarEntry(uri) : ""; + final String urlS = uriSchema+IOUtil.SCHEME_SEPARATOR+IOUtil.FILE_SCHEME+IOUtil.SCHEME_SEPARATOR+f.getPath()+post; + url = new URL(urlS); + mode = 2; + } + } + } + if( null == url ) { url = uri.toURL(); + mode = 3; + } + if( DEBUG ) { + System.err.println("IOUtil.toURL: "+uri+", isJar "+isJAR+": "+specificURI+" -> mode "+mode+", "+url); } return url; } diff --git a/src/java/com/jogamp/common/util/JarUtil.java b/src/java/com/jogamp/common/util/JarUtil.java index 665e196..481fe92 100644 --- a/src/java/com/jogamp/common/util/JarUtil.java +++ b/src/java/com/jogamp/common/util/JarUtil.java @@ -140,8 +140,9 @@ public class JarUtil { throw new IllegalArgumentException("null arguments: clazzBinName "+clazzBinName+", cl "+cl); } final URI uri; + final URL url; { - final URL url = IOUtil.getClassURL(clazzBinName, cl); + url = IOUtil.getClassURL(clazzBinName, cl); final String scheme = url.getProtocol(); if( null != resolver && !scheme.equals( IOUtil.JAR_SCHEME ) && @@ -165,6 +166,9 @@ public class JarUtil { if( !uri.getScheme().equals( IOUtil.JAR_SCHEME ) ) { throw new IllegalArgumentException("URI is not using scheme "+IOUtil.JAR_SCHEME+": <"+uri+">"); } + if(DEBUG) { + System.out.println("getJarURI res: "+clazzBinName+" -> "+url+" -> "+uri); + } return uri; } @@ -266,26 +270,27 @@ public class JarUtil { 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('!'); + final String uriS0 = classJarURI.getRawSchemeSpecificPart(); + int idx = uriS0.lastIndexOf('!'); + final String uriS1; if (0 <= idx) { - uriS = uriS.substring(0, idx); // exclude '!/' + uriS1 = uriS0.substring(0, idx); // exclude '!/' } else { throw new IllegalArgumentException("JAR URI does not contain jar uri terminator '!', uri <"+classJarURI+">"); } - if(0 >= uriS.lastIndexOf(".jar")) { + if(0 >= uriS1.lastIndexOf(".jar")) { throw new IllegalArgumentException("No Jar name in <"+classJarURI+">"); } if(DEBUG) { - System.out.println("getJarSubURI res: "+uriS); + System.out.println("getJarSubURI res: "+classJarURI+" -> "+uriS0+" -> "+uriS1+" -> "+uriS1); } - return new URI(uriS); + return new URI(uriS1); } /** -- cgit v1.2.3