1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.compress.harmony.unpack200.bytecode;
18
19 import java.io.DataOutputStream;
20 import java.io.IOException;
21 import java.util.Objects;
22
23
24
25
26 public abstract class Attribute extends ClassFileEntry {
27
28 protected final CPUTF8 attributeName;
29
30 private int attributeNameIndex;
31
32 public Attribute(final CPUTF8 attributeName) {
33 this.attributeName = attributeName;
34 }
35
36 @Override
37 protected void doWrite(final DataOutputStream dos) throws IOException {
38 dos.writeShort(attributeNameIndex);
39 dos.writeInt(getLength());
40 writeBody(dos);
41 }
42
43 @Override
44 public boolean equals(final Object obj) {
45 if (this == obj) {
46 return true;
47 }
48 if (obj == null) {
49 return false;
50 }
51 if (this.getClass() != obj.getClass()) {
52 return false;
53 }
54 final Attribute other = (Attribute) obj;
55 return Objects.equals(attributeName, other.attributeName);
56 }
57
58 protected CPUTF8 getAttributeName() {
59 return attributeName;
60 }
61
62 protected abstract int getLength();
63
64
65
66
67
68
69
70 protected int getLengthIncludingHeader() {
71 return getLength() + 2 + 4;
72 }
73
74 @Override
75 protected ClassFileEntry[] getNestedClassFileEntries() {
76 return new ClassFileEntry[] { getAttributeName() };
77 }
78
79
80
81
82
83
84 public boolean hasBCIRenumbering() {
85 return false;
86 }
87
88 @Override
89 public int hashCode() {
90 return Objects.hash(attributeName);
91 }
92
93
94
95
96
97
98 public boolean isSourceFileAttribute() {
99 return false;
100 }
101
102 @Override
103 protected void resolve(final ClassConstantPool pool) {
104 super.resolve(pool);
105 attributeNameIndex = pool.indexOf(attributeName);
106 }
107
108 protected abstract void writeBody(DataOutputStream dos) throws IOException;
109
110 }