Source code: com/techtrader/modules/tools/bytecode/UnknownAttribute.java
1 package com.techtrader.modules.tools.bytecode;
2
3
4 import java.io.DataInput;
5 import java.io.DataOutput;
6 import java.io.IOException;
7
8 import com.techtrader.modules.tools.bytecode.visitor.BCVisitor;
9
10
11 /**
12 * An unrecognized attribute; .class files are allowed to contain attributes
13 * that are not recognized, and the JVM must ignore them.
14 *
15 * @author Abe White
16 */
17 public class UnknownAttribute
18 extends Attribute
19 {
20 private byte[] _value = new byte[0];
21
22
23 public UnknownAttribute (int nameIndex, BCEntity owner)
24 {
25 super (nameIndex, owner);
26 }
27
28
29 /**
30 * The value's type is unknown, so just store the byte array.
31 */
32 public byte[] getValue ()
33 {
34 return _value;
35 }
36
37
38 /**
39 * The value's type is unknown, so just store the byte array.
40 */
41 public void setValue (byte[] value)
42 {
43 _value = value;
44 }
45
46
47 public int getLength ()
48 {
49 return _value.length;
50 }
51
52
53 protected void copy (Attribute other)
54 {
55 setValue (((UnknownAttribute) other).getValue ());
56 }
57
58
59 protected void readData (DataInput in, int length)
60 throws IOException
61 {
62 _value = new byte[length];
63 in.readFully (_value);
64 }
65
66
67 protected void writeData (DataOutput out, int length)
68 throws IOException
69 {
70 out.write (_value);
71 }
72
73
74 public void acceptVisit (BCVisitor visit)
75 {
76 visit.enterUnknownAttribute (this);
77 visit.exitUnknownAttribute (this);
78 }
79 }