KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > alt > jiapi > file > Attribute


1 package alt.jiapi.file;
2
3 import java.io.DataInputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5
6 /**
7  * Attribute.
8  *
9  * @author Mika Riekkinen
10  */

11 public class Attribute {
12     private short attribute_name_index;
13     private byte[] bytes;
14     protected ConstantPool cp;
15
16     protected Attribute(short nameIndex) {
17         this.attribute_name_index = nameIndex;
18     }
19     
20     Attribute(short nameIndex, int length, DataInputStream JavaDoc dis) throws IOException JavaDoc {
21         this.attribute_name_index = nameIndex;
22         this.bytes = new byte[length];
23         
24         for (int i = 0; i < length; i++) {
25             bytes[i] = dis.readByte();
26         }
27     }
28     
29     /**
30      * Get the bytes of this attribute.
31      *
32      * @return bytes representing this Attribute.
33      */

34     public byte[] getBytes() {
35         return bytes;
36     }
37
38     /**
39      * Get the name of this Attribute
40      *
41      * @return name of this attribute
42      */

43     public String JavaDoc getName() {
44         return cp.getUtf8(attribute_name_index);
45     }
46
47     short getAttributeNameIndex() {
48         return attribute_name_index;
49     }
50     
51     void setConstantPool(ConstantPool cp) {
52         this.cp = cp;
53     }
54 }
55
56
Popular Tags