Esempio n. 1
0
  public void save(XDataOutput out) {
    newContext();
    try {
      out.writeInt(magic);
      out.writeShort(minor);
      out.writeShort(major);

      ConstantPool pool = ConstantPool.create(true);
      registerConstants(pool);

      // cannot write directly to target (out):
      // pool must be written first but it is not completed
      // until all fields/methods/attributes and stuff is done
      ByteArrayDataOutput tmpout = new ByteArrayDataOutput();

      flags.save(tmpout);
      writeConstantReference(classname, tmpout);
      writeConstantReference(superclass, tmpout);

      // interfaces
      tmpout.writeShort(sizeof(interfaces));
      for (ClassRef i : iterable(interfaces)) {
        i.writeReference(tmpout);
      }

      save(tmpout, fields);
      save(tmpout, methods);
      save(tmpout, attributes);

      // done, ready to write the pool & the rest
      pool.save(out);
      out.write(tmpout.toByteArray());

    } finally {
      closeContext();
    }
  }
Esempio n. 2
0
 public byte[] toByteArray() {
   ByteArrayDataOutput out = new ByteArrayDataOutput();
   save(out);
   return out.toByteArray();
 }