home *** CD-ROM | disk | FTP | other *** search
- package com.sfs.hardcore;
-
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
-
- public class ConstantPoolInfo {
- int type;
- String name;
- ConstantPoolInfo arg1 = null;
- ConstantPoolInfo arg2 = null;
- short index1 = -1;
- short index2 = -1;
- String strValue;
- int intValue;
- long longValue;
- float floatValue;
- double doubleValue;
- public static final int CLASS = 7;
- public static final int FIELDREF = 9;
- public static final int METHODREF = 10;
- public static final int STRING = 8;
- public static final int INTEGER = 3;
- public static final int FLOAT = 4;
- public static final int LONG = 5;
- public static final int DOUBLE = 6;
- public static final int INTERFACE = 11;
- public static final int NAMEANDTYPE = 12;
- public static final int ASCIZ = 1;
- public static final int UNICODE = 2;
-
- public boolean isEqual(ConstantPoolInfo var1) {
- if (var1 == null) {
- return false;
- } else if (var1.type != this.type) {
- return false;
- } else {
- switch (var1.type) {
- case 1:
- case 2:
- if (var1.strValue.compareTo(this.strValue) != 0) {
- return false;
- }
-
- return true;
- case 3:
- if (var1.intValue != this.intValue) {
- return false;
- }
-
- return true;
- case 4:
- if (var1.floatValue != this.floatValue) {
- return false;
- }
-
- return true;
- case 5:
- if (var1.longValue != this.longValue) {
- return false;
- }
-
- return true;
- case 6:
- if (var1.doubleValue != this.doubleValue) {
- return false;
- }
-
- return true;
- case 7:
- case 8:
- if (this.arg1 != var1.arg1) {
- return false;
- }
-
- return true;
- case 9:
- case 10:
- case 11:
- case 12:
- if (this.arg1 == var1.arg1 && this.arg2 == var1.arg2) {
- return true;
- }
-
- return false;
- default:
- return false;
- }
- }
- }
-
- public String toString() {
- if (this.type == 1) {
- return this.strValue;
- } else if (this.type == 3) {
- return "= " + this.intValue;
- } else if (this.type == 5) {
- return "= " + this.longValue;
- } else if (this.type == 4) {
- return "= " + this.floatValue;
- } else if (this.type == 6) {
- return "= " + this.doubleValue;
- } else {
- StringBuffer var1 = new StringBuffer();
- var1.append(this.name);
- var1.append(":");
- if (this.arg1 != null) {
- var1.append(this.arg1.toString());
- } else if (this.index1 != -1) {
- var1.append("I1[" + this.index1 + "], ");
- }
-
- if (this.arg2 != null) {
- var1.append(this.arg2.toString());
- } else if (this.index2 != -1) {
- var1.append("I2[" + this.index2 + "], ");
- }
-
- return var1.toString();
- }
- }
-
- public boolean read(DataInputStream var1) throws IOException {
- this.type = var1.readByte();
- switch (this.type) {
- case 1:
- case 2:
- if (this.type == 1) {
- this.name = "ASCIZ";
- } else {
- this.name = "UNICODE";
- }
-
- StringBuffer var4 = new StringBuffer();
-
- for(int var2 = var1.readShort(); var2 > 0; --var2) {
- char var3 = (char)var1.readByte();
- var4.append(var3);
- }
-
- this.strValue = var4.toString();
- break;
- case 3:
- this.name = "Integer";
- this.intValue = var1.readInt();
- break;
- case 4:
- this.name = "Float";
- this.floatValue = var1.readFloat();
- break;
- case 5:
- this.name = "Long";
- this.longValue = var1.readLong();
- break;
- case 6:
- this.name = "Double";
- this.doubleValue = var1.readDouble();
- break;
- case 7:
- this.name = "Class";
- this.index1 = var1.readShort();
- this.index2 = -1;
- break;
- case 8:
- this.name = "String";
- this.index1 = var1.readShort();
- this.index2 = -1;
- break;
- case 9:
- this.name = "Field Reference";
- this.index1 = var1.readShort();
- this.index2 = var1.readShort();
- break;
- case 10:
- this.name = "Method Reference";
- this.index1 = var1.readShort();
- this.index2 = var1.readShort();
- break;
- case 11:
- this.name = "Interface Method Reference";
- this.index1 = var1.readShort();
- this.index2 = var1.readShort();
- break;
- case 12:
- this.name = "Name and Type";
- this.index1 = var1.readShort();
- this.index2 = var1.readShort();
- break;
- default:
- System.out.println("Warning bad type.");
- }
-
- return true;
- }
-
- public static short indexOf(ConstantPoolInfo var0, ConstantPoolInfo[] var1) throws Exception {
- for(int var2 = 0; var2 < var1.length; ++var2) {
- if (var0 == var1[var2]) {
- return (short)var2;
- }
- }
-
- throw new Exception("ConstantPoolInfo:: indexOf() - item not in pool.");
- }
-
- public void write(DataOutputStream var1, ConstantPoolInfo[] var2) throws IOException, Exception {
- var1.write(this.type);
- switch (this.type) {
- case 1:
- case 2:
- var1.writeShort(this.strValue.length());
- var1.writeBytes(this.strValue);
- return;
- case 3:
- var1.writeInt(this.intValue);
- return;
- case 4:
- var1.writeFloat(this.floatValue);
- return;
- case 5:
- var1.writeLong(this.longValue);
- return;
- case 6:
- var1.writeDouble(this.doubleValue);
- return;
- case 7:
- case 8:
- var1.writeShort(indexOf(this.arg1, var2));
- return;
- case 9:
- case 10:
- case 11:
- case 12:
- var1.writeShort(indexOf(this.arg1, var2));
- var1.writeShort(indexOf(this.arg2, var2));
- return;
- default:
- throw new Exception("ConstantPoolInfo::write() - bad type.");
- }
- }
-
- public ConstantPoolInfo(String var1) {
- this.type = 1;
- this.strValue = var1;
- }
-
- public ConstantPoolInfo(int var1) {
- this.type = 3;
- this.intValue = var1;
- }
-
- public ConstantPoolInfo(float var1) {
- this.type = 4;
- this.floatValue = var1;
- }
-
- public ConstantPoolInfo(long var1) {
- this.type = 5;
- this.longValue = var1;
- }
-
- public ConstantPoolInfo(double var1) {
- this.type = 6;
- this.doubleValue = var1;
- }
-
- public ConstantPoolInfo() {
- this.type = -1;
- }
-
- public ConstantPoolInfo inPool(ConstantPoolInfo[] var1) {
- for(int var2 = 1; var2 < var1.length; ++var2) {
- if (this.isEqual(var1[var2])) {
- return var1[var2];
- }
- }
-
- return null;
- }
-
- public int isType() {
- return this.type;
- }
- }
-