Ich möchte eine Java class Datei einlesen und frage mich, wie ich das am besten mache.
Ich dachte an sowas:
Ist das eine gute Strategie oder ist es sinnvoller z.B. eine HashMap zu verwenden und dort den Inhalt der class Datei rein zu schreiben.
Ich dachte an sowas:
Java:
class DataIn extends DataInputStream {
int u1() {
return readUnsignedByte();
}
int u2() {
return readUnsignedShort();
}
int u4() {
return readInt();
}
}
class ClassFile {
...
int numMethods;
Method[] methods;
...
ClassFile(DataIn in) {
...
numMethods=in.u2();
methods=new Methods[numMethods];
for(int i=0; i<numMethods; i++) methods[i]=new Method(in);
...
}
}
class Method {
...
int numAttributes;
Attribute[] attributes;
...
Method(DataIn in) {
...
numAttributes=in.u2();
attributes=new Attribute[numAttributes];
for(int i=0; i<numAttributes; i++) attributes[i]=new Attribute(in);
...
}
}
Ist das eine gute Strategie oder ist es sinnvoller z.B. eine HashMap zu verwenden und dort den Inhalt der class Datei rein zu schreiben.