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