/*
  * Returns the URL for a resource with the specified name
  */
 URL findResource(final String name, boolean check) {
   Resource rsc = getResource(name, check);
   if (rsc != null) {
     return rsc.getURL();
   }
   return null;
 }
Exemplo n.º 2
0
 public URL nextElement() {
   if (!next()) {
     throw new NoSuchElementException();
   } else {
     Resource resource = myRes;
     myRes = null;
     return resource.getURL();
   }
 }
 /*
  * Defines a Class using the class bytes obtained from the specified
  * Resource. The resulting Class must be resolved before it can be
  * used.
  */
 private Class<?> _defineClass(String name, Resource res) throws IOException {
   long t0 = System.nanoTime();
   int i = name.lastIndexOf('.');
   URL url = res.getCodeSourceURL();
   if (i != -1) {
     String pkgname = name.substring(0, i);
     // Check if package already loaded.
     Manifest man = res.getManifest();
     _definePackageInternal(pkgname, man, url);
   }
   // Now read the class bytes and define the class
   java.nio.ByteBuffer bb = res.getByteBuffer();
   if (bb != null) {
     // Use (direct) ByteBuffer:
     CodeSigner[] signers = res.getCodeSigners();
     CodeSource cs = new CodeSource(url, signers);
     sun.misc.PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0);
     return defineClass(name, bb, cs);
   } else {
     byte[] b = res.getBytes();
     // must read certificates AFTER reading bytes.
     CodeSigner[] signers = res.getCodeSigners();
     CodeSource cs = new CodeSource(url, signers);
     sun.misc.PerfCounter.getReadClassBytesTime().addElapsedTimeFrom(t0);
     return defineClass(name, b, 0, b.length, cs);
   }
 }
Exemplo n.º 4
0
  @SuppressWarnings("UseOfSystemOutOrSystemErr")
  private static synchronized void printOrder(Loader loader, String url, Resource resource) {
    if (!ourDumpOrder) return;
    if (!ourOrderedUrls.add(url)) return;

    String home = FileUtil.toSystemIndependentName(PathManager.getHomePath());
    try {
      ourOrderSize += resource.getContentLength();
    } catch (IOException e) {
      e.printStackTrace(System.out);
    }

    if (ourOrder == null) {
      final File orderFile = new File(PathManager.getBinPath() + File.separator + "order.txt");
      try {
        if (!FileUtil.ensureCanCreateFile(orderFile)) return;
        ourOrder = new PrintStream(new FileOutputStream(orderFile, true));
        ShutDownTracker.getInstance()
            .registerShutdownTask(
                new Runnable() {
                  public void run() {
                    ourOrder.close();
                    System.out.println(ourOrderSize);
                  }
                });
      } catch (IOException e) {
        return;
      }
    }

    if (ourOrder != null) {
      String jarURL = FileUtil.toSystemIndependentName(loader.getBaseURL().getFile());
      jarURL = StringUtil.trimStart(jarURL, "file:/");
      if (jarURL.startsWith(home)) {
        jarURL = jarURL.replaceFirst(home, "");
        jarURL = StringUtil.trimEnd(jarURL, "!/");
        ourOrder.println(url + ":" + jarURL);
      }
    }
  }
 public int getContentLength() throws IOException {
   return delegatedResource == null ? null : delegatedResource.getContentLength();
 }
 public InputStream getInputStream() throws IOException {
   return delegatedResource == null ? null : delegatedResource.getInputStream();
 }
 public URL getCodeSourceURL() {
   return delegatedResource == null ? null : delegatedResource.getCodeSourceURL();
 }