private void registerConstants(ConstantPool pool) { classname = pool.register(classname); superclass = pool.register(superclass); interfaces = Helper.register(interfaces, pool); for (FieldInfo f : iterable(fields)) { f.registerConstants(pool); } for (MethodInfo m : iterable(methods)) { m.registerConstants(pool); } for (AttributeInfo a : iterable(attributes)) { a.registerConstants(pool); } pool.rebuild(); }
protected Task readConstantDataOrGetResolver(XDataInput in, ConstantPool pool) { readLength(in); int count = in.readUnsignedShort(); items = new ArrayList<Item>(count); while (count-- > 0) { Item item = new Item(); item.startpc = in.readUnsignedShort(); item.length = in.readUnsignedShort(); item.name = pool.getConstant(in.readUnsignedShort(), Utf8.class); item.signature = pool.getConstant(in.readUnsignedShort(), Utf8.class); items.add(item); } return null; }
public void load(XDataInput in) { newContext(); try { magic = in.readInt(); minor = in.readUnsignedShort(); major = in.readUnsignedShort(); pool = ConstantPool.create(true); pool.load(in, pool); flags = Flags.create(in, pool); classname = pool.getConstant(in.readUnsignedShort(), ClassRef.class); Log.debug("Loading class %s", classname.value()); superclass = pool.getConstant(in.readUnsignedShort(), ClassRef.class); // interfaces { int count = in.readUnsignedShort(); interfaces = new ArrayList<ClassRef>(count); while (count-- > 0) { ClassRef iface = pool.getConstant(in.readUnsignedShort(), ClassRef.class); interfaces.add(iface); } } // fields { int count = in.readUnsignedShort(); fields = new ArrayList<FieldInfo>(count); while (count-- > 0) { FieldInfo f = new FieldInfo(this); f.load(in, pool); fields.add(f); } } // methods { int count = in.readUnsignedShort(); methods = new ArrayList<MethodInfo>(count); while (count-- > 0) { MethodInfo m = new MethodInfo(this); m.load(in, pool); methods.add(m); } } attributes = AttributeHelper.loadAttributes(this, in); AttributeHelper.qdhRemoveUnsupportedAttributes(attributes); pool.close(); } finally { closeContext(); } }
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(); } }