Index: PathVFSJavaLoader.java =================================================================== RCS file: /cvsroot/jython/jython/Lib/jxxload_help/PathVFSJavaLoader.java,v retrieving revision 1.1 diff -u -r1.1 PathVFSJavaLoader.java --- PathVFSJavaLoader.java 2001/01/15 04:51:57 1.1 +++ PathVFSJavaLoader.java 2002/01/31 23:13:31 @@ -2,53 +2,80 @@ package jxxload_help; +import java.io.InputStream; + + public class PathVFSJavaLoader extends ClassLoader { - private ClassLoader parent; - - private PathVFS vfs; - - public java.util.Vector interfaces = new java.util.Vector(); + private ClassLoader parent; + private byte[] buf = new byte[4096]; + private PathVFS vfs; - public PathVFSJavaLoader(PathVFS vfs,ClassLoader parent) { - this.vfs = vfs; - this.parent = parent; - } + public java.util.Vector interfaces = new java.util.Vector(); - protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - Class c; + public PathVFSJavaLoader(PathVFS vfs,ClassLoader parent) { + this.vfs = vfs; + this.parent = parent; + } + + private void reallocate() { + byte[] newbuf = new byte[buf.length * 2]; + System.arraycopy(buf, 0, newbuf, 0, buf.length); + buf = newbuf; + } + + + public InputStream getResourceAsStream(String param1) { + InputStream result; + if (parent != null) + result = parent.getResourceAsStream(param1); + if (result == null) + result = vfs.open(param1); + return result; + } + + + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + Class c; - c = findLoadedClass(name); - if (c != null) return c; + c = findLoadedClass(name); + if (c != null) return c; - try { - if (parent != null) return parent.loadClass(name); - } catch(ClassNotFoundException e) { - } + try { + if (parent != null) return parent.loadClass(name); + } catch(ClassNotFoundException e) { + } - java.io.InputStream in = vfs.open(name.replace('.','/')+".class"); - if (in == null) throw new ClassNotFoundException(name); + java.io.InputStream in = vfs.open(name.replace('.','/')+".class"); + if (in == null) throw new ClassNotFoundException(name); - try { - int av = in.available(); - byte[] buf = new byte[av]; - in.read(buf); - in.close(); - return loadClassFromBytes(name,buf); - } catch(java.io.IOException e) { - throw new ClassNotFoundException(name); - } + try { + int used = 0; + while(true) { + int count = in.read(buf, used, buf.length - used);; + if (count < 0) + break; + used += count; + if (used >= buf.length) + reallocate(); + } + in.close(); + return loadClassFromBytes(name,buf,used); + } catch(java.io.IOException e) { + throw new ClassNotFoundException(name); + } - } + } - private Class loadClassFromBytes(String name, byte[] data) { - Class c = defineClass(name, data, 0, data.length); - resolveClass(c); - if (c.isInterface()) interfaces.addElement(c); - if (!org.python.core.Options.skipCompile) { - Compiler.compileClass(c); - } - return c; - } + private Class loadClassFromBytes(String name, byte[] data, int length) { + Class c = defineClass(name, data, 0, length); + resolveClass(c); + if (c.isInterface()) interfaces.addElement(c); + if (!org.python.core.Options.skipCompile) { + Compiler.compileClass(c); + } + return c; + } -} \ No newline at end of file +} +