* Serializes this class. The produced byte array is in the class file format.
* It may be written to a .class file and it may be loaded by a <code>ClassLoader</code>.
* @return the class data.
*/
public byte[] getData() {
ByteSerializer ser = new ByteSerializer(true);
// 0:
ser.addBytes(ClassFile.magic);
// 4:
ser.addShort(getMinorVersion());
ser.addShort(getMajorVersion());
// 8:
ser.addBytes(this.pool.getData());
// 8+pooldata:
ser.addShort(this.accessFlags);
ser.addShort(this.thisClass);
ser.addShort(this.superClass);
// 14+pooldata:
ser.addShort(this.interfaces.size());
// 16+pooldata:
for (Interface anInterface : this.interfaces) {
ser.addShort(anInterface.getNameIndex());
}
// 16+pooldata+interfaces*2
ser.addShort(this.fields.size());
// 18+pooldata+interfaces*2
for (Field field : this.fields) {
ser.addBytes(field.getData());
}
// 18+pooldata+interfaces*2+fielddata
ser.addShort(this.methods.size());
// 20+pooldata+interfaces*2+fielddata
for (Method method : this.methods) {
ser.addBytes(method.getData());
}
// 20+pooldata+interfaces*2+fielddata+methoddata
ser.addBytes(this.attributes.getData());
return ser.getBytes();
}