ClassReaderpublic class ClassReader extends Object
Fields Summary |
---|
int | verbosity | ConstantPool | t |
Constructors Summary |
---|
public ClassReader(ConstantPool cp, int verb)
t = cp;
verbosity = verb;
|
Methods Summary |
---|
private int | getMagic(java.io.InputStream file)
DataInputStream data = new DataInputStream( file );
int n = 0;
file.mark( 4 );
try {
n = data.readInt();
} finally {
file.reset();
}
return n;
| public int | readClass(java.lang.String classname, ClassFileFinder finder, java.util.Vector done)
InputStream f = finder.findClassFile( classname );
if ( f == null ) return 0;
try {
return readStream( classname, f, done );
} catch ( IOException e ){
e.printStackTrace();
return 0;
}
| public int | readFile(java.lang.String fileName, java.util.Vector done)
InputStream infile;
infile = new BufferedInputStream(new FileInputStream( fileName ) );
return readStream(fileName, infile, done);
| public int | readStream(java.lang.String inputName, java.io.InputStream infile, java.util.Vector done)
int magicNumber = getMagic( infile );
int ndone = 0;
if ( magicNumber == Const.JAVA_MAGIC ){
/*
* We have a solo class.
*/
ClassFile f = new ClassFile( inputName, infile, verbosity>=2 );
if ( verbosity != 0 )
System.out.println(
Localizer.getString("classreader.reading_classfile",
inputName));
if (f.readClassFile( t ) ){
f.clas.externalize( t );
done.addElement( f.clas );
ndone+=1;
} else {
throw new DataFormatException(
Localizer.getString("classreader.read_of_class_file",
inputName));
}
} else {
throw new DataFormatException(
Localizer.getString("classreader.file_has_bad_magic_number",
inputName, Integer.toString(magicNumber)));
}
try {
infile.close();
} catch ( Throwable x ){ }
return ndone;
| public int | readZip(java.lang.String fileName, java.util.Vector done)
ZipEntry ent;
int i = 0;
ZipInputStream zip =
new ZipInputStream(new FileInputStream(fileName));
while ((ent = zip.getNextEntry()) != null) {
String name = ent.getName();
if (!ent.isDirectory() &&
(name.endsWith(".class") || name.endsWith(".mclass"))) {
try {
byte buffer[] = readZipEntry(zip);
i += readStream(name, new ByteArrayInputStream(buffer),
done);
} catch (IOException e) {
System.out.println(Localizer.getString("classreader.failed_on", name));
}
}
}
return i;
| byte[] | readZipEntry(java.util.zip.ZipInputStream zip)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buff = new byte[1024];
int len;
while (true) {
len = zip.read(buff, 0, buff.length);
if (len == -1) {
break;
}
baos.write(buff, 0, len);
}
return baos.toByteArray();
|
|