Package gnu.java.net.loader

Examples of gnu.java.net.loader.Resource


    throws ClassNotFoundException
  {
    // Just try to find the resource by the (almost) same name
    String resourceName = className.replace('.', '/') + ".class";
    int max = urlinfos.size();
    Resource resource = null;
    for (int i = 0; i < max && resource == null; i++)
      {
        URLLoader loader = (URLLoader)urlinfos.elementAt(i);
        if (loader == null)
          continue;

        Class k = loader.getClass(className);
        if (k != null)
          return k;

        resource = loader.getResource(resourceName);
      }
    if (resource == null)
      throw new ClassNotFoundException(className + " not found in " + this);

    // Try to read the class data, create the CodeSource, Package and
    // construct the class (and watch out for those nasty IOExceptions)
    try
      {
        byte[] data;
        InputStream in = resource.getInputStream();
        try
          {
            int length = resource.getLength();
            if (length != -1)
              {
                // We know the length of the data.
                // Just try to read it in all at once
                data = new byte[length];
                int pos = 0;
                while (length - pos > 0)
                  {
                    int len = in.read(data, pos, length - pos);
                    if (len == -1)
                      throw new EOFException("Not enough data reading from: "
                                             + in);
                    pos += len;
                  }
              }
            else
              {
                // We don't know the data length.
                // Have to read it in chunks.
                ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
                byte[] b = new byte[4096];
                int l = 0;
                while (l != -1)
                  {
                    l = in.read(b);
                    if (l != -1)
                      out.write(b, 0, l);
                  }
                data = out.toByteArray();
              }
          }
        finally
          {
            in.close();
          }
        final byte[] classData = data;

        // Now get the CodeSource
        final CodeSource source = resource.getCodeSource();

        // Find out package name
        String packageName = null;
        int lastDot = className.lastIndexOf('.');
        if (lastDot != -1)
          packageName = className.substring(0, lastDot);

        if (packageName != null && getPackage(packageName) == null)
          {
            // define the package
            Manifest manifest = resource.getLoader().getManifest();
            if (manifest == null)
              definePackage(packageName, null, null, null, null, null, null,
                            null);
            else
              definePackage(packageName, manifest,
                            resource.getLoader().getBaseURL());
          }

        // And finally construct the class!
        SecurityManager sm = System.getSecurityManager();
        Class result = null;
        if (sm != null && securityContext != null)
          {
            result = (Class)AccessController.doPrivileged
              (new PrivilegedAction()
                {
                  public Object run()
                  {
                    return defineClass(className, classData,
                                       0, classData.length,
                                       source);
                  }
                }, securityContext);
          }
        else
          result = defineClass(className, classData, 0, classData.length, source);

        // Avoid NullPointerExceptions.
        Certificate[] resourceCertificates = resource.getCertificates();
        if(resourceCertificates != null)
          super.setSigners(result, resourceCertificates);

        return result;
      }
View Full Code Here


      {
        URLLoader loader = (URLLoader) urlinfos.elementAt(i);
        if (loader == null)
          continue;

        Resource resource = loader.getResource(resourceName);
        if (resource != null)
          return resource;
      }
    return null;
  }
View Full Code Here

   * @param resourceName the resource name to look for
   * @return the URL if found, null otherwise
   */
  public URL findResource(String resourceName)
  {
    Resource resource = findURLResource(resourceName);
    if (resource != null)
      return resource.getURL();

    // Resource not found
    return null;
  }
View Full Code Here

    Vector resources = new Vector();
    int max = urlinfos.size();
    for (int i = 0; i < max; i++)
      {
        URLLoader loader = (URLLoader) urlinfos.elementAt(i);
        Resource resource = loader.getResource(resourceName);
        if (resource != null)
          resources.add(resource.getURL());
      }
    return resources.elements();
  }
View Full Code Here

    throws ClassNotFoundException
  {
    // Just try to find the resource by the (almost) same name
    String resourceName = className.replace('.', '/') + ".class";
    int max = urlinfos.size();
    Resource resource = null;
    for (int i = 0; i < max && resource == null; i++)
      {
        URLLoader loader = (URLLoader)urlinfos.elementAt(i);
        if (loader == null)
          continue;

        Class k = loader.getClass(className);
        if (k != null)
          return k;

        resource = loader.getResource(resourceName);
      }
    if (resource == null)
      throw new ClassNotFoundException(className + " not found in " + this);

    // Try to read the class data, create the CodeSource, Package and
    // construct the class (and watch out for those nasty IOExceptions)
    try
      {
  byte[] data;
  InputStream in = resource.getInputStream();
  try
    {
      int length = resource.getLength();
      if (length != -1)
        {
    // We know the length of the data.
    // Just try to read it in all at once
    data = new byte[length];
    int pos = 0;
    while (length - pos > 0)
      {
        int len = in.read(data, pos, length - pos);
        if (len == -1)
          throw new EOFException("Not enough data reading from: "
               + in);
        pos += len;
      }
        }
      else
        {
    // We don't know the data length.
    // Have to read it in chunks.
    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    byte[] b = new byte[4096];
    int l = 0;
    while (l != -1)
      {
        l = in.read(b);
        if (l != -1)
          out.write(b, 0, l);
      }
    data = out.toByteArray();
        }
    }
  finally
    {
      in.close();
    }
  final byte[] classData = data;

        // Now get the CodeSource
        final CodeSource source = resource.getCodeSource();

        // Find out package name
        String packageName = null;
        int lastDot = className.lastIndexOf('.');
        if (lastDot != -1)
          packageName = className.substring(0, lastDot);

        if (packageName != null && getPackage(packageName) == null)
          {
            // define the package
            Manifest manifest = resource.getLoader().getManifest();
            if (manifest == null)
              definePackage(packageName, null, null, null, null, null, null,
                            null);
            else
              definePackage(packageName, manifest,
                            resource.getLoader().getBaseURL());
          }

        // And finally construct the class!
        SecurityManager sm = System.getSecurityManager();
        Class result = null;
        if (sm != null && securityContext != null)
          {
            result = AccessController.doPrivileged
              (new PrivilegedAction<Class>()
                {
                  public Class run()
                  {
                    return defineClass(className, classData,
                                       0, classData.length,
                                       source);
                  }
                }, securityContext);
          }
        else
          result = defineClass(className, classData, 0, classData.length, source);

        // Avoid NullPointerExceptions.
        Certificate[] resourceCertificates = resource.getCertificates();
        if(resourceCertificates != null)
          super.setSigners(result, resourceCertificates);
       
        return result;
      }
View Full Code Here

      {
        URLLoader loader = (URLLoader) urlinfos.elementAt(i);
        if (loader == null)
          continue;

        Resource resource = loader.getResource(resourceName);
        if (resource != null)
          return resource;
      }
    return null;
  }
View Full Code Here

   * @param resourceName the resource name to look for
   * @return the URL if found, null otherwise
   */
  public URL findResource(String resourceName)
  {
    Resource resource = findURLResource(resourceName);
    if (resource != null)
      return resource.getURL();

    // Resource not found
    return null;
  }
View Full Code Here

    Vector<URL> resources = new Vector<URL>();
    int max = urlinfos.size();
    for (int i = 0; i < max; i++)
      {
        URLLoader loader = (URLLoader) urlinfos.elementAt(i);
        Resource resource = loader.getResource(resourceName);
        if (resource != null)
          resources.add(resource.getURL());
      }
    return resources.elements();
  }
View Full Code Here

TOP

Related Classes of gnu.java.net.loader.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.