protected Class findClass()

in jpa-container/src/main/java/org/apache/aries/jpa/container/parser/impl/TempBundleDelegatingClassLoader.java [61:102]


    protected Class<?> findClass(String className) throws ClassNotFoundException {
        String classResName = className.replace('.', '/').concat(".class");

        // Don't use loadClass, just load the bytes and call defineClass
        Bundle currentContext = currentLoadingBundle.get().peek();
        InputStream is;
        if (currentContext == null) {
            is = getResourceAsStream(classResName);
        } else {
            is = getResourceInBundleAsStream(classResName, currentContext);
        }

        if (is == null) {
            throw new ClassNotFoundException(className);
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        byte[] buff = new byte[4096];
        try {
            try {
                int read = is.read(buff);
                while (read > 0) {
                    baos.write(buff, 0, read);
                    read = is.read(buff);
                }
            } finally {
                is.close();
            }
        } catch (IOException ioe) {
            throw new ClassNotFoundException(className, ioe);
        }

        buff = baos.toByteArray();

        updateContext(currentContext, className);
        try {
            return defineClass(className, buff, 0, buff.length);
        } finally {
            currentLoadingBundle.get().pop();
        }
    }