git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@88 30ef5769-5b8d-40dd-aea6-55b5d6557bb3tags/rel_3_17_1_ga
@@ -440,10 +440,10 @@ public class ClassPool { | |||
/* for CtClassType.getClassFile2(). Don't delegate to the parent. | |||
*/ | |||
byte[] readSource(String classname) | |||
throws NotFoundException, IOException, CannotCompileException | |||
InputStream openClassfile(String classname) | |||
throws NotFoundException | |||
{ | |||
return source.readSource(classname); | |||
return source.openClassfile(classname); | |||
} | |||
void writeClassfile(String classname, OutputStream out) |
@@ -224,20 +224,6 @@ final class ClassPoolTail { | |||
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. | |||
*/ | |||
@@ -275,32 +261,6 @@ final class ClassPoolTail { | |||
*/ | |||
/** | |||
* Obtains the contents of the class file for the class | |||
* specified by <code>classname</code>. | |||
* | |||
* @param classname a fully-qualified class name | |||
* @return null if the file has not been found. | |||
* @throws NotFoundException if any error is reported by ClassPath. | |||
*/ | |||
private byte[] readClassfile(String classname) | |||
throws NotFoundException, IOException | |||
{ | |||
InputStream fin = openClassfile(classname); | |||
if (fin == null) | |||
return null; | |||
byte[] b; | |||
try { | |||
b = readStream(fin); | |||
} | |||
finally { | |||
fin.close(); | |||
} | |||
return b; | |||
} | |||
/** | |||
* Opens the class file for the class specified by | |||
* <code>classname</code>. | |||
@@ -309,7 +269,7 @@ final class ClassPoolTail { | |||
* @return null if the file has not been found. | |||
* @throws NotFoundException if any error is reported by ClassPath. | |||
*/ | |||
private InputStream openClassfile(String classname) | |||
InputStream openClassfile(String classname) | |||
throws NotFoundException | |||
{ | |||
if (packages.get(classname) != null) |
@@ -19,7 +19,6 @@ import javassist.bytecode.*; | |||
import javassist.compiler.Javac; | |||
import javassist.compiler.CompileError; | |||
import javassist.expr.ExprEditor; | |||
import java.io.ByteArrayInputStream; | |||
import java.io.InputStream; | |||
import java.io.DataInputStream; | |||
import java.io.DataOutputStream; | |||
@@ -108,11 +107,14 @@ class CtClassType extends CtClass { | |||
if (classfile != null) | |||
return classfile; | |||
InputStream fin = null; | |||
try { | |||
byte[] b = classPool.readSource(getName()); | |||
DataInputStream dis | |||
= new DataInputStream(new ByteArrayInputStream(b)); | |||
return (classfile = new ClassFile(dis)); | |||
fin = classPool.openClassfile(getName()); | |||
if (fin == null) | |||
throw new NotFoundException(getName()); | |||
classfile = new ClassFile(new DataInputStream(fin)); | |||
return classfile; | |||
} | |||
catch (NotFoundException e) { | |||
throw new RuntimeException(e.toString()); | |||
@@ -120,8 +122,12 @@ class CtClassType extends CtClass { | |||
catch (IOException e) { | |||
throw new RuntimeException(e.toString()); | |||
} | |||
catch (CannotCompileException e) { | |||
throw new RuntimeException(e.toString()); | |||
finally { | |||
if (fin != null) | |||
try { | |||
fin.close(); | |||
} | |||
catch (IOException e) {} | |||
} | |||
} | |||
@@ -21,7 +21,7 @@ import java.io.ByteArrayOutputStream; | |||
import java.io.PrintWriter; | |||
import java.io.IOException; | |||
import java.util.Map; | |||
import java.util.Hashtable; | |||
import java.util.HashMap; | |||
import javassist.CtClass; | |||
/** | |||
@@ -30,10 +30,9 @@ import javassist.CtClass; | |||
public final class ConstPool { | |||
LongVector items; | |||
int numOfItems; | |||
Hashtable classes; | |||
Hashtable strings; | |||
HashMap classes; | |||
HashMap strings; | |||
int thisClassInfo; | |||
private static final int SIZE = 128; | |||
/** | |||
* <code>CONSTANT_Class</code> | |||
@@ -103,7 +102,11 @@ public final class ConstPool { | |||
* pool table | |||
*/ | |||
public ConstPool(String thisclass) { | |||
this(); | |||
items = new LongVector(); | |||
numOfItems = 0; | |||
addItem(null); // index 0 is reserved by the JVM. | |||
classes = new HashMap(); | |||
strings = new HashMap(); | |||
thisClassInfo = addClassInfo(thisclass); | |||
} | |||
@@ -113,17 +116,12 @@ public final class ConstPool { | |||
* @param in byte stream. | |||
*/ | |||
public ConstPool(DataInputStream in) throws IOException { | |||
this(); | |||
read(in); | |||
} | |||
private ConstPool() { | |||
items = new LongVector(SIZE); | |||
numOfItems = 0; | |||
addItem(null); // index 0 is reserved by the JVM. | |||
classes = new Hashtable(); | |||
strings = new Hashtable(); | |||
classes = new HashMap(); | |||
strings = new HashMap(); | |||
thisClassInfo = 0; | |||
/* read() initializes items and numOfItems, and do addItem(null). | |||
*/ | |||
read(in); | |||
} | |||
/** | |||
@@ -861,6 +859,12 @@ public final class ConstPool { | |||
private void read(DataInputStream in) throws IOException { | |||
int n = in.readUnsignedShort(); | |||
int size = (n / LongVector.SIZE + 1) * LongVector.SIZE; | |||
items = new LongVector(size); | |||
numOfItems = 0; | |||
addItem(null); // index 0 is reserved by the JVM. | |||
while (--n > 0) { // index 0 is reserved by JVM | |||
int tag = readOne(in); | |||
if ((tag == LongInfo.tag) || (tag == DoubleInfo.tag)) { |
@@ -16,10 +16,15 @@ | |||
package javassist.bytecode; | |||
final class LongVector { | |||
static final int SIZE = 128; | |||
private int num; | |||
private Object[] objects; | |||
private LongVector next; | |||
public LongVector() { | |||
this(SIZE); | |||
} | |||
public LongVector(int initialSize) { | |||
num = 0; | |||
objects = new Object[initialSize]; | |||
@@ -34,7 +39,7 @@ final class LongVector { | |||
if (p.num < p.objects.length) | |||
p.objects[p.num++] = obj; | |||
else { | |||
LongVector q = p.next = new LongVector(p.objects.length); | |||
LongVector q = p.next = new LongVector(SIZE); | |||
q.objects[q.num++] = obj; | |||
} | |||
} |