code: public void writeTo(DataOutput dout) throws IOException {
          dout.writeInt(MAGIC);
          dout.writeInt(mVersion);
  
          mCp.writeTo(dout);
  
          {
              int flags = mModifiers.getBitmask();
              if (!mModifiers.isInterface()) {
                  // Set the ACC_SUPER flag for classes only.
                  flags |= Modifier.SYNCHRONIZED;
              }
              dout.writeShort(flags);
          }
  
          dout.writeShort(mThisClass.getIndex());
          if (mSuperClass != null) {
              dout.writeShort(mSuperClass.getIndex());
          } else {
              dout.writeShort(0);
          }
          
          int size = mInterfaces.size();
          if (size > 65535) {
              throw new IllegalStateException("Interfaces count cannot exceed 65535: " + size);
          }
          dout.writeShort(size);
          for (int i=0; i<size; i++) {
              int index = mInterfaces.get(i).getIndex();
              dout.writeShort(index);
          }
          
          size = mFields.size();
          if (size > 65535) {
              throw new IllegalStateException("Field count cannot exceed 65535: " + size);
          }
          dout.writeShort(size);
          for (int i=0; i<size; i++) {
              FieldInfo field = mFields.get(i);
              field.writeTo(dout);
          }
          
          size = mMethods.size();
          if (size > 65535) {
              throw new IllegalStateException("Method count cannot exceed 65535: " + size);
          }
          dout.writeShort(size);
          for (int i=0; i<size; i++) {
              MethodInfo method = mMethods.get(i);
              method.writeTo(dout);
          }
          
          size = mAttributes.size();
          if (size > 65535) {
              throw new IllegalStateException("Attribute count cannot exceed 65535: " + size);
          }
          dout.writeShort(size);
          for (int i=0; i<size; i++) {
              Attribute attr = mAttributes.get(i);
              attr.writeTo(dout);
          }
      }
docs: Writes the ClassFile to the given DataOutput.