public virtual byte[] ToByteArray()
{
int dataSize = GetWriteSize();
byte[] data = new byte[dataSize];
int offset = 0;
short sourceFileAttributeNameIndex = 0;
if (itsSourceFileNameIndex != 0)
{
sourceFileAttributeNameIndex = itsConstantPool.AddUtf8("SourceFile");
}
offset = PutInt32(FileHeaderConstant, data, offset);
offset = PutInt16(MinorVersion, data, offset);
offset = PutInt16(MajorVersion, data, offset);
offset = itsConstantPool.Write(data, offset);
offset = PutInt16(itsFlags, data, offset);
offset = PutInt16(itsThisClassIndex, data, offset);
offset = PutInt16(itsSuperClassIndex, data, offset);
offset = PutInt16(itsInterfaces.Size(), data, offset);
for (int i = 0; i < itsInterfaces.Size(); i++)
{
int interfaceIndex = System.Convert.ToInt16(((short)(itsInterfaces.Get(i))));
offset = PutInt16(interfaceIndex, data, offset);
}
offset = PutInt16(itsFields.Size(), data, offset);
for (int i_1 = 0; i_1 < itsFields.Size(); i_1++)
{
ClassFileField field = (ClassFileField)itsFields.Get(i_1);
offset = field.Write(data, offset);
}
offset = PutInt16(itsMethods.Size(), data, offset);
for (int i_2 = 0; i_2 < itsMethods.Size(); i_2++)
{
ClassFileMethod method = (ClassFileMethod)itsMethods.Get(i_2);
offset = method.Write(data, offset);
}
if (itsSourceFileNameIndex != 0)
{
offset = PutInt16(1, data, offset);
// attributes count
offset = PutInt16(sourceFileAttributeNameIndex, data, offset);
offset = PutInt32(2, data, offset);
offset = PutInt16(itsSourceFileNameIndex, data, offset);
}
else
{
offset = PutInt16(0, data, offset);
}
// no attributes
if (offset != dataSize)
{
// Check getWriteSize is consistent with write!
throw new Exception();
}
return data;
}