From b98825eb7cfb61aead4a7dff57471cd2d2c26823 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sun, 9 Jun 2013 05:33:16 +0200
Subject: Fix Bug 683 part1: IOUtil, JarUtil, TempJarCache, .. uses URI instead
 of URL to remove DNS Lookups etc ..

---
 src/java/com/jogamp/common/os/NativeLibrary.java | 15 +++++++++++--
 src/java/com/jogamp/common/os/Platform.java      | 28 ++++++++++++------------
 2 files changed, 27 insertions(+), 16 deletions(-)

(limited to 'src/java/com/jogamp/common/os')

diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java
index 130812c..2351391 100644
--- a/src/java/com/jogamp/common/os/NativeLibrary.java
+++ b/src/java/com/jogamp/common/os/NativeLibrary.java
@@ -50,6 +50,7 @@ import jogamp.common.os.WindowsDynamicLinkerImpl;
 
 import java.io.*;
 import java.lang.reflect.*;
+import java.net.URISyntaxException;
 import java.security.*;
 import java.util.*;
 
@@ -254,7 +255,12 @@ public class NativeLibrary implements DynamicLookupHelper {
    * @return basename of libName w/o path, ie. /usr/lib/libDrinkBeer.so -> DrinkBeer on Unix systems, but null on Windows.
    */
   public static String isValidNativeLibraryName(String libName, boolean isLowerCaseAlready) {
-    final String libBaseName = IOUtil.getBasename(libName);
+    final String libBaseName;
+    try {
+        libBaseName = IOUtil.getBasename(libName);
+    } catch (URISyntaxException uriEx) {
+        throw new IllegalArgumentException(uriEx);
+    }
     final String libBaseNameLC = isLowerCaseAlready ? libBaseName : libBaseName.toLowerCase();
     int prefixIdx = -1;
     for(int i=0; i<prefixes.length && 0 > prefixIdx; i++) {    
@@ -405,7 +411,12 @@ public class NativeLibrary implements DynamicLookupHelper {
       // If the library name already has the prefix / suffix added
       // (principally because we want to force a version number on Unix
       // operating systems) then just return the library name.
-      final String libBaseNameLC = IOUtil.getBasename(libName).toLowerCase();
+      final String libBaseNameLC;
+      try {
+          libBaseNameLC = IOUtil.getBasename(libName).toLowerCase();
+      } catch (URISyntaxException uriEx) {
+          throw new IllegalArgumentException(uriEx);
+      }
       
       int prefixIdx = -1;
       for(int i=0; i<prefixes.length && 0 > prefixIdx; i++) {    
diff --git a/src/java/com/jogamp/common/os/Platform.java b/src/java/com/jogamp/common/os/Platform.java
index e58e72c..aa9bccd 100644
--- a/src/java/com/jogamp/common/os/Platform.java
+++ b/src/java/com/jogamp/common/os/Platform.java
@@ -28,7 +28,7 @@
  
 package com.jogamp.common.os;
 
-import java.net.URL;
+import java.net.URI;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.concurrent.TimeUnit;
@@ -162,19 +162,19 @@ public class Platform extends PlatformPropsImpl {
     /** <code>true</code> if AWT is available and not in headless mode, otherwise <code>false</code>. */
     public static final boolean AWT_AVAILABLE;
         
-    private static final URL platformClassJarURL;
+    private static final URI platformClassJarURI;
     
     static {
         PlatformPropsImpl.initSingleton(); // just documenting the order of static initialization
 
         {
-            URL _platformClassJarURL;
+            URI _platformClassJarURI;
             try {
-                _platformClassJarURL = JarUtil.getJarURL(Platform.class.getName(), Platform.class.getClassLoader());
+                _platformClassJarURI = JarUtil.getJarURI(Platform.class.getName(), Platform.class.getClassLoader());
             } catch (Exception e) { 
-                _platformClassJarURL = null; 
+                _platformClassJarURI = null; 
             }
-            platformClassJarURL = _platformClassJarURL;
+            platformClassJarURI = _platformClassJarURI;
         }
 
         USE_TEMP_JAR_CACHE = (OS_TYPE != OSType.ANDROID) && isRunningFromJarURL() &&
@@ -228,24 +228,24 @@ public class Platform extends PlatformPropsImpl {
      * @return true if we're running from a Jar URL, otherwise false
      */
     public static final boolean isRunningFromJarURL() {        
-        return null != platformClassJarURL;
+        return null != platformClassJarURI;
     }
     
     private static final void loadGlueGenRTImpl() {
         if(USE_TEMP_JAR_CACHE && TempJarCache.initSingleton()) {
             String nativeJarName = null;
-            URL jarUrlRoot = null;
-            URL nativeJarURL = null;
+            URI jarUriRoot = null;
+            URI nativeJarURI = null;
             try {
-                final String jarName = JarUtil.getJarBasename(platformClassJarURL);
+                final String jarName = JarUtil.getJarBasename(platformClassJarURI);
                 final String nativeJarBasename = jarName.substring(0, jarName.indexOf(".jar")); // ".jar" already validated w/ JarUtil.getJarBasename(..)
                 nativeJarName = nativeJarBasename+"-natives-"+PlatformPropsImpl.os_and_arch+".jar";                    
-                jarUrlRoot = JarUtil.getURLDirname( JarUtil.getJarSubURL(platformClassJarURL) );
-                nativeJarURL = JarUtil.getJarFileURL(jarUrlRoot, nativeJarName);
-                TempJarCache.bootstrapNativeLib(Platform.class, libBaseName, nativeJarURL);
+                jarUriRoot = JarUtil.getURIDirname( JarUtil.getJarSubURI( platformClassJarURI ) );
+                nativeJarURI = JarUtil.getJarFileURI(jarUriRoot, nativeJarName);
+                TempJarCache.bootstrapNativeLib(Platform.class, libBaseName, nativeJarURI);
             } catch (Exception e0) {
                 // IllegalArgumentException, IOException
-                System.err.println("Catched "+e0.getClass().getSimpleName()+": "+e0.getMessage()+", while TempJarCache.bootstrapNativeLib() of "+nativeJarURL+" ("+jarUrlRoot+" + "+nativeJarName+")");
+                System.err.println("Catched "+e0.getClass().getSimpleName()+": "+e0.getMessage()+", while TempJarCache.bootstrapNativeLib() of "+nativeJarURI+" ("+jarUriRoot+" + "+nativeJarName+")");
             }
         }
         DynamicLibraryBundle.GlueJNILibLoader.loadLibrary(libBaseName, false, Platform.class.getClassLoader());
-- 
cgit v1.2.3