コード例 #1
0
  /** Load class from this JAR only. */
  private synchronized Class _loadClass(String clazz, boolean resolveIt)
      throws ClassNotFoundException {
    jar.activatePlugin();

    synchronized (this) {
      Class cls = findLoadedClass(clazz);
      if (cls != null) {
        if (resolveIt) resolveClass(cls);
        return cls;
      }

      String name = MiscUtilities.classToFile(clazz);

      try {
        definePackage(clazz);
        ZipFile zipFile = jar.getZipFile();
        ZipEntry entry = zipFile.getEntry(name);

        if (entry == null) throw new ClassNotFoundException(clazz);

        InputStream in = zipFile.getInputStream(entry);

        int len = (int) entry.getSize();
        byte[] data = new byte[len];
        int success = 0;
        int offset = 0;
        while (success < len) {
          len -= success;
          offset += success;
          success = in.read(data, offset, len);
          if (success == -1) {
            Log.log(
                Log.ERROR, this, "Failed to load class " + clazz + " from " + zipFile.getName());
            throw new ClassNotFoundException(clazz);
          }
        }

        cls = defineClass(clazz, data, 0, data.length);

        if (resolveIt) resolveClass(cls);

        return cls;
      } catch (IOException io) {
        Log.log(Log.ERROR, this, io);

        throw new ClassNotFoundException(clazz);
      }
    }
  } // }}}
コード例 #2
0
  // {{{ definePackage(packageName, manifest) method
  private void definePackage(String name, Manifest mf) {
    if (mf == null) {
      definePackage(name, null, null, null, null, null, null, null);
      return;
    }

    Attributes sa = mf.getAttributes(name.replace('.', '/') + '/');
    Attributes ma = mf.getMainAttributes();

    URL sealBase = null;
    if (Boolean.valueOf(getMfValue(sa, ma, Name.SEALED)).booleanValue()) {
      try {
        sealBase = jar.getFile().toURL();
      } catch (MalformedURLException e) {
      }
    }

    Package pkg =
        definePackage(
            name,
            getMfValue(sa, ma, Name.SPECIFICATION_TITLE),
            getMfValue(sa, ma, Name.SPECIFICATION_VERSION),
            getMfValue(sa, ma, Name.SPECIFICATION_VENDOR),
            getMfValue(sa, ma, Name.IMPLEMENTATION_TITLE),
            getMfValue(sa, ma, Name.IMPLEMENTATION_VERSION),
            getMfValue(sa, ma, Name.IMPLEMENTATION_VENDOR),
            sealBase);
  } // }}}
コード例 #3
0
 // {{{ definePackage(clazz) method
 private void definePackage(String clazz) throws IOException {
   int idx = clazz.lastIndexOf('.');
   if (idx != -1) {
     String name = clazz.substring(0, idx);
     if (getPackage(name) == null) definePackage(name, new JarFile(jar.getFile()).getManifest());
   }
 } // }}}