From 55bc1f3da24f0e815beeac617f06cf809e774577 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 27 Apr 1999 18:20:13 +0000 Subject: [PATCH] some simplification of AttributeInfo, may not work, AttributeInfo is removed now git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@656 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/bytecode/AttributeInfo.java | 43 ++++++++++++++++++--------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/jode/jode/bytecode/AttributeInfo.java b/jode/jode/bytecode/AttributeInfo.java index d80a9c4..7291c5c 100644 --- a/jode/jode/bytecode/AttributeInfo.java +++ b/jode/jode/bytecode/AttributeInfo.java @@ -28,25 +28,31 @@ public class AttributeInfo { String name; byte[] data; - public AttributeInfo() { + public AttributeInfo(String name) { + this.name = name; + } + + public AttributeInfo(String name, byte[] data) { + this.name = name; + this.data = data; } public void read(ConstantPool constantPool, DataInputStream input, int howMuch) throws IOException { - String attrName = constantPool.getUTF8(input.readUnsignedShort()); int length = input.readInt(); - if ((howMuch & ClassInfo.ALL_ATTRIBUTES) != 0) { - name = attrName; - data = new byte[length]; - input.readFully(data); - } else { - while (length > 0) { - int skipped = (int) input.skip(length); - if (skipped == 0) - throw new EOFException("Can't skip. EOF?"); - length -= skipped; - } - } + data = new byte[length]; + input.readFully(data); + } + + public void prepareWriting(GrowableConstantPool gcp) { + gcp.putUTF8(name); + } + + public void write(GrowableConstantPool constantPool, + DataOutputStream output) throws IOException { + output.writeShort(constantPool.putUTF8(name)); + output.writeInt(data.length); + output.write(data); } public String getName() { @@ -86,4 +92,13 @@ public class AttributeInfo { writer.println("*/"); } } + + public boolean equals(Object o) { + return (o instanceof AttributeInfo + && ((AttributeInfo) o).name.equals(name)); + } + + public int hashCode() { + return name.hashCode(); + } }