diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2004-04-14 15:49:55 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2004-04-14 15:49:55 +0000 |
commit | 3f73777f2cdf408d47bd85417611635235bdd7ed (patch) | |
tree | c0d6156cae1ca72e8ec2f3c36b8b83bcaae30916 /src/main/javassist/ClassPoolTail.java | |
parent | 2d7afcd04b007ef3322b132d82f3f32889414232 (diff) | |
download | javassist-3f73777f2cdf408d47bd85417611635235bdd7ed.tar.gz javassist-3f73777f2cdf408d47bd85417611635235bdd7ed.zip |
modified the ClassPool framework.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@84 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/ClassPoolTail.java')
-rw-r--r-- | src/main/javassist/ClassPoolTail.java | 152 |
1 files changed, 93 insertions, 59 deletions
diff --git a/src/main/javassist/ClassPoolTail.java b/src/main/javassist/ClassPoolTail.java index 4abe8e7c..5cfc2933 100644 --- a/src/main/javassist/ClassPoolTail.java +++ b/src/main/javassist/ClassPoolTail.java @@ -128,7 +128,7 @@ final class JarClassPath implements ClassPath { } } -final class ClassPoolTail extends AbsClassPool { +final class ClassPoolTail { protected ClassPathList pathList; private Hashtable packages; // should be synchronized. @@ -151,62 +151,6 @@ final class ClassPoolTail extends AbsClassPool { return buf.toString(); } - /** - * You can record "System" so that java.lang.System can be quickly - * found although "System" is not a package name. - */ - public void recordInvalidClassName(String name) { - packages.put(name, name); - } - - /** - * @return the contents of the class file. - * @throws NotFoundException if the file could not be found. - */ - byte[] readSource(String classname) - throws NotFoundException, IOException, CannotCompileException - { - byte[] b = readClassfile(classname); - if (b == null) - throw new NotFoundException(classname); - else - return b; - } - - /** - * @return null if the file could not be found. - * @throws NotFoundException if any error is reported by ClassPath. - */ - boolean write0(String classname, DataOutputStream out, boolean callback) - throws NotFoundException, CannotCompileException, IOException - { - byte[] b = readClassfile(classname); - if (b == null) - return false; // not found - else { - out.write(b, 0, b.length); - return true; - } - } - - /* - -- faster version -- - void checkClassName(String classname) throws NotFoundException { - if (find(classname) == null) - throw new NotFoundException(classname); - } - - -- slower version -- - - void checkClassName(String classname) throws NotFoundException { - InputStream fin = openClassfile(classname); - try { - fin.close(); - } - catch (IOException e) {} - } - */ - public synchronized ClassPath insertClassPath(ClassPath cp) { pathList = new ClassPathList(cp, pathList); return cp; @@ -273,6 +217,65 @@ final class ClassPoolTail extends AbsClassPool { } /** + * You can record "System" so that java.lang.System can be quickly + * found although "System" is not a package name. + */ + public void recordInvalidClassName(String name) { + packages.put(name, name); + } + + /** + * @return the contents of the class file. + * @throws NotFoundException if the file could not be found. + */ + byte[] readSource(String classname) + throws NotFoundException, IOException, CannotCompileException + { + byte[] b = readClassfile(classname); + if (b == null) + throw new NotFoundException(classname); + else + return b; + } + + /** + * This method does not close the output stream. + */ + void writeClassfile(String classname, OutputStream out) + throws NotFoundException, IOException, CannotCompileException + { + InputStream fin = openClassfile(classname); + if (fin == null) + throw new NotFoundException(classname); + + try { + copyStream(fin, out); + } + finally { + fin.close(); + } + } + + /* + -- faster version -- + void checkClassName(String classname) throws NotFoundException { + if (find(classname) == null) + throw new NotFoundException(classname); + } + + -- slower version -- + + void checkClassName(String classname) throws NotFoundException { + InputStream fin = openClassfile(classname); + try { + fin.close(); + } + catch (IOException e) {} + } + */ + + + /** * Obtains the contents of the class file for the class * specified by <code>classname</code>. * @@ -337,7 +340,9 @@ final class ClassPoolTail extends AbsClassPool { } /** - * Obtains the URL of the class file specified by classname. + * Searches the class path to obtain the URL of the class file + * specified by classname. It is also used to determine whether + * the class file exists. * * @param classname a fully-qualified class name. * @return null if the class file could not be found. @@ -360,7 +365,7 @@ final class ClassPoolTail extends AbsClassPool { } /** - * Reads an input stream until it reaches the end. + * Reads from an input stream until it reaches the end. * * @return the contents of that input stream */ @@ -393,4 +398,33 @@ final class ClassPoolTail extends AbsClassPool { throw new IOException("too much data"); } + + /** + * Reads from an input stream and write to an output stream + * until it reaches the end. This method does not close the + * streams. + */ + public static void copyStream(InputStream fin, OutputStream fout) + throws IOException + { + int bufsize = 4096; + for (int i = 0; i < 8; ++i) { + byte[] buf = new byte[bufsize]; + int size = 0; + int len = 0; + do { + len = fin.read(buf, size, bufsize - size); + if (len >= 0) + size += len; + else { + fout.write(buf, 0, size); + return; + } + } while (size < bufsize); + fout.write(buf); + bufsize *= 2; + } + + throw new IOException("too much data"); + } } |