FileDocCategorySizeDatePackage
PublicClassLoader.javaAPI DocAndroid 1.5 API3337Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.tests.java.lang

PublicClassLoader

public class PublicClassLoader extends ClassLoader

Fields Summary
Constructors Summary
public PublicClassLoader()

            super();
        
public PublicClassLoader(ClassLoader cl)

            super(cl);
        
Methods Summary
public java.lang.ClassdefineClassTest(byte[] b, int off, int len)

            return defineClass(b, off, len);
        
private byte[]getBytes(java.lang.String filename)

            
            File file = new File( filename );
            long len = file.length();
            byte raw[] = new byte[(int)len];
            FileInputStream fin = new FileInputStream( file );
            int r = fin.read( raw );
            if (r != len)
              throw new IOException( "Can't read all, "+r+" != "+len );
            fin.close();
            return raw;
          
public java.lang.PackagegetPackage(java.lang.String name)

            return super.getPackage(name);
        
public java.lang.Package[]getPackages()

            return super.getPackages();
        
public java.io.InputStreamgetResourceAsStream(java.lang.String name)

            return getClass().getResourceAsStream("/" + getClass().getPackage().
                    getName().replace(".", "/") + "/" + name);
        
public java.lang.ClassloadClass(java.lang.String name, boolean resolve)

            
            Class clazz = findLoadedClass(name);
            String classFileName = name.replace( '.", '/" ) + ".class";
            File classFile = new File(classFileName);
            if (classFile.exists()) {
                try {
                    byte raw[] = getBytes(classFileName);
                    clazz = defineClass( name, raw, 0, raw.length );
                } catch(Exception ioe) {}
            }
            
            if (clazz == null) {
                Package p = getClass().getPackage();
                InputStream is = getResourceAsStream("/" + classFileName);
                byte[] buf = new byte[512];
                int len;
                try {
                    len = is.read(buf);
                    clazz = defineClass(name, buf, 0, len);                    
                } catch (IOException e) {
                }
            }            
            
            if (clazz == null) {
                clazz = findSystemClass(name);
            }

            if(clazz == null)
                throw new ClassNotFoundException(name);
            return clazz;