⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 constpool.java

📁 Javassist是一个开源的分析、编辑和创建Java字节码的类库。是由东京技术学院的数学和计算机科学系的 Shigeru Chiba 所创建的。它已加入了开放源代码JBoss 应用服务器项目,通过使
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            break;        default :            throw new IOException("invalid constant type: " + tag);        }        addItem(info);        return tag;    }    /**     * Writes the contents of the constant pool table.     */    public void write(DataOutputStream out) throws IOException {        out.writeShort(numOfItems);        LongVector v = items;        int size = numOfItems;        for (int i = 1; i < size; ++i)            ((ConstInfo)v.elementAt(i)).write(out);    }    /**     * Prints the contents of the constant pool table.     */    public void print() {        print(new PrintWriter(System.out, true));    }    /**     * Prints the contents of the constant pool table.     */    public void print(PrintWriter out) {        int size = numOfItems;        for (int i = 1; i < size; ++i) {            out.print(i);            out.print(" ");            ((ConstInfo)items.elementAt(i)).print(out);        }    }}abstract class ConstInfo {    public abstract int getTag();    public String getClassName(ConstPool cp) { return null; }    public void renameClass(ConstPool cp, String oldName, String newName) {}    public void renameClass(ConstPool cp, Map classnames) {}    public abstract int copy(ConstPool src, ConstPool dest, Map classnames);                        // ** classnames is a mapping between JVM names.    public abstract void write(DataOutputStream out) throws IOException;    public abstract void print(PrintWriter out);    void makeHashtable(ConstPool cp) {}     // called after read() finishes in ConstPool.    public String toString() {        ByteArrayOutputStream bout = new ByteArrayOutputStream();        PrintWriter out = new PrintWriter(bout);        print(out);        return bout.toString();    }}/* padding following DoubleInfo or LongInfo. */class ConstInfoPadding extends ConstInfo {    public int getTag() { return 0; }    public int copy(ConstPool src, ConstPool dest, Map map) {        return dest.addConstInfoPadding();    }    public void write(DataOutputStream out) throws IOException {}    public void print(PrintWriter out) {        out.println("padding");    }}class ClassInfo extends ConstInfo {    static final int tag = 7;    int name;    int index;    public ClassInfo(int className, int i) {        name = className;        index = i;    }    public ClassInfo(DataInputStream in, int i) throws IOException {        name = in.readUnsignedShort();        index = i;    }    public int getTag() { return tag; }    public String getClassName(ConstPool cp) {        return cp.getUtf8Info(name);    };    public void renameClass(ConstPool cp, String oldName, String newName) {        String nameStr = cp.getUtf8Info(name);        if (nameStr.equals(oldName))            name = cp.addUtf8Info(newName);        else if (nameStr.charAt(0) == '[') {            String nameStr2 = Descriptor.rename(nameStr, oldName, newName);            if (nameStr != nameStr2)                name = cp.addUtf8Info(nameStr2);        }    }    public void renameClass(ConstPool cp, Map map) {        String oldName = cp.getUtf8Info(name);        if (oldName.charAt(0) == '[') {            String newName = Descriptor.rename(oldName, map);            if (oldName != newName)                name = cp.addUtf8Info(newName);        }        else {            String newName = (String)map.get(oldName);            if (newName != null && !newName.equals(oldName))                name = cp.addUtf8Info(newName);        }    }    public int copy(ConstPool src, ConstPool dest, Map map) {        String classname = src.getUtf8Info(name);        if (map != null) {            String newname = (String)map.get(classname);            if (newname != null)                classname = newname;        }        return dest.addClassInfo(classname);    }    public void write(DataOutputStream out) throws IOException {        out.writeByte(tag);        out.writeShort(name);    }    public void print(PrintWriter out) {        out.print("Class #");        out.println(name);    }    void makeHashtable(ConstPool cp) {        String name = Descriptor.toJavaName(getClassName(cp));        cp.classes.put(name, this);    }}class NameAndTypeInfo extends ConstInfo {    static final int tag = 12;    int memberName;    int typeDescriptor;    public NameAndTypeInfo(int name, int type) {        memberName = name;        typeDescriptor = type;    }    public NameAndTypeInfo(DataInputStream in) throws IOException {        memberName = in.readUnsignedShort();        typeDescriptor = in.readUnsignedShort();    }    public int getTag() { return tag; }    public void renameClass(ConstPool cp, String oldName, String newName) {        String type = cp.getUtf8Info(typeDescriptor);        String type2 = Descriptor.rename(type, oldName, newName);        if (type != type2)            typeDescriptor = cp.addUtf8Info(type2);    }    public void renameClass(ConstPool cp, Map map) {        String type = cp.getUtf8Info(typeDescriptor);        String type2 = Descriptor.rename(type, map);        if (type != type2)            typeDescriptor = cp.addUtf8Info(type2);    }    public int copy(ConstPool src, ConstPool dest, Map map) {        String mname = src.getUtf8Info(memberName);        String tdesc = src.getUtf8Info(typeDescriptor);        tdesc = Descriptor.rename(tdesc, map);        return dest.addNameAndTypeInfo(dest.addUtf8Info(mname),                                       dest.addUtf8Info(tdesc));    }    public void write(DataOutputStream out) throws IOException {        out.writeByte(tag);        out.writeShort(memberName);        out.writeShort(typeDescriptor);    }    public void print(PrintWriter out) {        out.print("NameAndType #");        out.print(memberName);        out.print(", type #");        out.println(typeDescriptor);    }}abstract class MemberrefInfo extends ConstInfo {    int classIndex;    int nameAndTypeIndex;    public MemberrefInfo(int cindex, int ntindex) {        classIndex = cindex;        nameAndTypeIndex = ntindex;    }    public MemberrefInfo(DataInputStream in) throws IOException {        classIndex = in.readUnsignedShort();        nameAndTypeIndex = in.readUnsignedShort();    }    public int copy(ConstPool src, ConstPool dest, Map map) {        int classIndex2 = src.getItem(classIndex).copy(src, dest, map);        int ntIndex2 = src.getItem(nameAndTypeIndex).copy(src, dest, map);        return copy2(dest, classIndex2, ntIndex2);    }    abstract protected int copy2(ConstPool dest, int cindex, int ntindex);    public void write(DataOutputStream out) throws IOException {        out.writeByte(getTag());        out.writeShort(classIndex);        out.writeShort(nameAndTypeIndex);    }    public void print(PrintWriter out) {        out.print(getTagName() + " #");        out.print(classIndex);        out.print(", name&type #");        out.println(nameAndTypeIndex);    }    public abstract String getTagName();}class FieldrefInfo extends MemberrefInfo {    static final int tag = 9;    public FieldrefInfo(int cindex, int ntindex) {        super(cindex, ntindex);    }    public FieldrefInfo(DataInputStream in) throws IOException {        super(in);    }    public int getTag() { return tag; }    public String getTagName() { return "Field"; }    protected int copy2(ConstPool dest, int cindex, int ntindex) {        return dest.addFieldrefInfo(cindex, ntindex);    }}class MethodrefInfo extends MemberrefInfo {    static final int tag = 10;    public MethodrefInfo(int cindex, int ntindex) {        super(cindex, ntindex);    }    public MethodrefInfo(DataInputStream in) throws IOException {        super(in);    }    public int getTag() { return tag; }    public String getTagName() { return "Method"; }    protected int copy2(ConstPool dest, int cindex, int ntindex) {        return dest.addMethodrefInfo(cindex, ntindex);    }}class InterfaceMethodrefInfo extends MemberrefInfo {    static final int tag = 11;    public InterfaceMethodrefInfo(int cindex, int ntindex) {        super(cindex, ntindex);    }    public InterfaceMethodrefInfo(DataInputStream in) throws IOException {        super(in);    }    public int getTag() { return tag; }    public String getTagName() { return "Interface"; }    protected int copy2(ConstPool dest, int cindex, int ntindex) {        return dest.addInterfaceMethodrefInfo(cindex, ntindex);    }}class StringInfo extends ConstInfo {    static final int tag = 8;    int string;    public StringInfo(int str) {        string = str;    }    public StringInfo(DataInputStream in) throws IOException {        string = in.readUnsignedShort();    }    public int getTag() { return tag; }    public int copy(ConstPool src, ConstPool dest, Map map) {        return dest.addStringInfo(src.getUtf8Info(string));    }    public void write(DataOutputStream out) throws IOException {        out.writeByte(tag);        out.writeShort(string);    }    public void print(PrintWriter out) {        out.print("String #");        out.println(string);    }}class IntegerInfo extends ConstInfo {    static final int tag = 3;    int value;    public IntegerInfo(int i) {        value = i;    }    public IntegerInfo(DataInputStream in) throws IOException {        value = in.readInt();    }    public int getTag() { return tag; }    public int copy(ConstPool src, ConstPool dest, Map map) {        return dest.addIntegerInfo(value);    }    public void write(DataOutputStream out) throws IOException {        out.writeByte(tag);        out.writeInt(value);    }    public void print(PrintWriter out) {        out.print("Integer ");        out.println(value);    }}class FloatInfo extends ConstInfo {    static final int tag = 4;    float value;    public FloatInfo(float f) {        value = f;    }    public FloatInfo(DataInputStream in) throws IOException {        value = in.readFloat();    }    public int getTag() { return tag; }    public int copy(ConstPool src, ConstPool dest, Map map) {        return dest.addFloatInfo(value);    }    public void write(DataOutputStream out) throws IOException {        out.writeByte(tag);        out.writeFloat(value);    }    public void print(PrintWriter out) {        out.print("Float ");        out.println(value);    }}class LongInfo extends ConstInfo {    static final int tag = 5;    long value;    public LongInfo(long l) {        value = l;    }    public LongInfo(DataInputStream in) throws IOException {        value = in.readLong();    }    public int getTag() { return tag; }    public int copy(ConstPool src, ConstPool dest, Map map) {        return dest.addLongInfo(value);    }    public void write(DataOutputStream out) throws IOException {        out.writeByte(tag);        out.writeLong(value);    }    public void print(PrintWriter out) {        out.print("Long ");        out.println(value);    }}class DoubleInfo extends ConstInfo {    static final int tag = 6;    double value;    public DoubleInfo(double d) {        value = d;    }    public DoubleInfo(DataInputStream in) throws IOException {        value = in.readDouble();    }    public int getTag() { return tag; }    public int copy(ConstPool src, ConstPool dest, Map map) {        return dest.addDoubleInfo(value);    }    public void write(DataOutputStream out) throws IOException {        out.writeByte(tag);        out.writeDouble(value);    }    public void print(PrintWriter out) {        out.print("Double ");        out.println(value);    }}class Utf8Info extends ConstInfo {    static final int tag = 1;    String string;    int index;    public Utf8Info(String utf8, int i) {        string = utf8;        index = i;    }    public Utf8Info(DataInputStream in, int i) throws IOException {        string = in.readUTF();        index = i;    }    public int getTag() { return tag; }    public int copy(ConstPool src, ConstPool dest, Map map) {        return dest.addUtf8Info(string);    }    public void write(DataOutputStream out) throws IOException {        out.writeByte(tag);        out.writeUTF(string);    }    public void print(PrintWriter out) {        out.print("UTF8 \"");        out.print(string);        out.println("\"");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -