예제 #1
0
  /**
   * 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>
   *
   * Example #1
   *
   * <pre>
   *   classFromJavaJar = com.lighting.Test (in: file:/storage/TestLighting.jar)
   *   cutOffInclSubDir = lights/
   *   relResPath       = LightAssets.jar
   *   Result           : file:/storage/lights/LightAssets.jar
   * </pre>
   *
   * Example #2
   *
   * <pre>
   *   classFromJavaJar = com.lighting.Test (in: file:/storage/lights/TestLighting.jar)
   *   cutOffInclSubDir = lights/
   *   relResPath       = LightAssets.jar
   *   Result           : file:/storage/lights/LightAssets.jar
   * </pre>
   *
   * TODO: Enhance documentation!
   *
   * @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.
   * @throws IllegalArgumentException
   * @throws IOException
   * @throws 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);
    if (DEBUG) {
      System.err.println(
          "JarUtil.getRelativeOf: "
              + "(classFromJavaJar "
              + classFromJavaJar
              + ", classJarUri "
              + classJarUri
              + ", cutOffInclSubDir "
              + cutOffInclSubDir
              + ", relResPath "
              + relResPath
              + "): ");
    }

    final Uri jarSubUri = classJarUri.getContainedUri();
    if (null == jarSubUri) {
      throw new IllegalArgumentException("JarSubUri is null of: " + classJarUri);
    }
    final Uri.Encoded jarUriRoot = jarSubUri.getDirectory().getEncoded();
    if (DEBUG) {
      System.err.println(
          "JarUtil.getRelativeOf: " + "uri " + jarSubUri.toString() + " -> " + jarUriRoot);
    }

    final Uri.Encoded resUri;
    if (jarUriRoot.endsWith(cutOffInclSubDir.get())) {
      resUri = jarUriRoot.concat(relResPath);
    } else {
      resUri = jarUriRoot.concat(cutOffInclSubDir).concat(relResPath);
    }
    if (DEBUG) {
      System.err.println("JarUtil.getRelativeOf: " + "...  -> " + resUri);
    }

    final Uri resJarUri = JarUtil.getJarFileUri(resUri);
    if (DEBUG) {
      System.err.println("JarUtil.getRelativeOf: " + "fin " + resJarUri);
    }
    return resJarUri;
  }
예제 #2
0
 private synchronized Font abspath(final String fname, final int family, final int style)
     throws IOException {
   if (!attemptedJARLoading) {
     attemptedJARLoading = true;
     Platform.initSingleton();
     if (TempJarCache.isInitialized()) {
       try {
         final Uri uri = JarUtil.getRelativeOf(UbuntuFontLoader.class, jarSubDir, jarName);
         final Exception e0 =
             AccessController.doPrivileged(
                 new PrivilegedAction<Exception>() {
                   @Override
                   public Exception run() {
                     try {
                       TempJarCache.addResources(UbuntuFontLoader.class, uri);
                       useTempJARCache = true;
                       return null;
                     } catch (final Exception e) {
                       return e;
                     }
                   }
                 });
         if (null != e0) {
           throw e0;
         }
       } catch (final Exception e1) {
         System.err.println("Caught " + e1.getMessage());
         e1.printStackTrace();
       }
     }
   }
   final String path = useTempJARCache ? absFontPath : relFontPath;
   try {
     final Font f = abspathImpl(path + fname, family, style);
     if (null != f) {
       return f;
     }
     throw new IOException(
         String.format("Problem loading font %s, stream %s%s", fname, path, fname));
   } catch (final Exception e) {
     throw new IOException(
         String.format("Problem loading font %s, stream %s%s", fname, path, fname), e);
   }
 }
예제 #3
0
  @Override
  public void run() {
    // // Necessary to load the native libraries correctly (see
    // //
    // http://forum.jogamp.org/Return-of-the-quot-java-lang-UnsatisfiedLinkError-Can-t-load-library-System-Library-Frameworks-glueg-td4034549.html)
    JarUtil.setResolver(
        new JarUtil.Resolver() {

          @Override
          public URL resolve(final URL url) {
            try {
              final URL urlUnescaped = FileLocator.resolve(url);
              final URL urlEscaped =
                  new URI(urlUnescaped.getProtocol(), urlUnescaped.getPath(), null).toURL();
              return urlEscaped;
            } catch (final IOException ioexception) {
              return url;
            } catch (final URISyntaxException urisyntaxexception) {
              return url;
            }
          }
        });

    // Necessary to initialize very early because initializing it
    // while opening a Java2D view before leads to a deadlock
    GLProfile.initSingleton();
    while (!GLProfile.isInitialized()) {
      try {
        Thread.sleep(100);
      } catch (final InterruptedException e) {
        e.printStackTrace();
      }
    }

    isInitialized = true;
  }