package cutils.classDumper;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class AttributeInfo {
ConstantPoolInfo name;
byte data[];
public AttributeInfo(ConstantPoolInfo newName, byte newData[]) {
name = name;
data = newData;
}
public AttributeInfo() {
}
public boolean read(DataInputStream di, ConstantPoolInfo pool[])
throws IOException {
int len;
name = pool[di.readShort()];
len = di.readInt();
data = new byte[len];
len = di.read(data);
if (len != data.length)
return (false);
return (true);
}
public void write(DataOutputStream dos, ConstantPoolInfo pool[])
throws IOException, Exception {
dos.writeShort(ConstantPoolInfo.indexOf(name, pool));
dos.writeInt(data.length);
dos.write(data, 0, data.length);
}
short indexFromBytes(byte a[]) {
return (short) (((a[0] << 8) & (0xff << 8)) |
((a[1] << 0) & (0xff << 0)));
}
public String toString(ConstantPoolInfo pool[]) {
StringBuffer x = new StringBuffer();
String type = name.toString();
ConstantPoolInfo item;
if (type.compareTo("ConstantValue") == 0) {
item = pool[indexFromBytes(data)];
return (item.toString());
} else if (type.compareTo("SourceFile") == 0) {
item = pool[indexFromBytes(data)];
return (item.toString());
} else {
x.append(type + "<" + data.length + " bytes>");
}
return (x.toString());
}
public String toBoolean(ConstantPoolInfo pool[]) {
ConstantPoolInfo item = pool[indexFromBytes(data)];
if (item.intValue == 0)
return ("= false");
return ("= true");
}
public String toString() {
return (name.toString() + " <" + data.length + " bytes>");
}
}