docs: public byte[] toByteArray() {
          short bootstrapMethodsAttrNameIndex = 0;
          int attributeCount = 0;
  
          short sourceFileAttributeNameIndex = 0;
          if (itsBootstrapMethods != null) {
              ++attributeCount;
              bootstrapMethodsAttrNameIndex = itsConstantPool.addUtf8("BootstrapMethods");
          }
  
          if (itsSourceFileNameIndex != 0) {
              ++attributeCount;
              sourceFileAttributeNameIndex = itsConstantPool.addUtf8(
                  "SourceFile");
          }
  
          // Don't calculate the data size until we know how many bootstrap
          // methods there will be.
          int offset = 0;
          int dataSize = getWriteSize();
          byte[] data = new byte[dataSize];
  
          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 = ((Short) (itsInterfaces.get(i))).shortValue();
              offset = putInt16(interfaceIndex, data, offset);
          }
          offset = putInt16(itsFields.size(), data, offset);
          for (int i = 0; i < itsFields.size(); i++) {
              ClassFileField field = (ClassFileField) itsFields.get(i);
              offset = field.write(data, offset);
          }
          offset = putInt16(itsMethods.size(), data, offset);
          for (int i = 0; i < itsMethods.size(); i++) {
              ClassFileMethod method = (ClassFileMethod) itsMethods.get(i);
              offset = method.write(data, offset);
          }
          offset = putInt16(attributeCount, data, offset); // attributes count
          if (itsBootstrapMethods != null) {
              offset = putInt16(bootstrapMethodsAttrNameIndex, data, offset);
              offset = putInt32(itsBootstrapMethodsLength + 2, data, offset);
              offset = putInt16(itsBootstrapMethods.size(), data, offset);
              for (int i = 0; i < itsBootstrapMethods.size(); i++) {
                  BootstrapEntry entry = (BootstrapEntry) itsBootstrapMethods.get(i);
                  System.arraycopy(entry.code, 0, data, offset, entry.code.length);
                  offset += entry.code.length;
              }
          }
          if (itsSourceFileNameIndex != 0) {
              offset = putInt16(sourceFileAttributeNameIndex, data, offset);
              offset = putInt32(2, data, offset);
              offset = putInt16(itsSourceFileNameIndex, data, offset);
          }
  
          if (offset != dataSize) {
              // Check getWriteSize is consistent with write!
              throw new RuntimeException();
          }
  
          return data;
      }