KickJava   Java API By Example, From Geeks To Geeks.

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


1 package alt.jiapi.file;
2
3 import java.io.ByteArrayOutputStream JavaDoc;
4 import java.io.DataInputStream JavaDoc;
5 import java.io.DataOutputStream JavaDoc;
6 import java.io.IOException JavaDoc;
7 import java.util.List JavaDoc;
8 import java.util.LinkedList JavaDoc;
9 import java.util.Iterator JavaDoc;
10
11 /**
12  * Class CodeAttribute.
13  *
14  * @author Mika Riekkinen
15  * @see Java Virtual Machine Specification 2nd edition, ch. 4.7.2
16  */

17 public class ConstantValueAttribute extends Attribute {
18     private short[] bytes = new short[1];
19
20     ConstantValueAttribute(short nameIndex, DataInputStream JavaDoc dis) throws IOException JavaDoc {
21         super(nameIndex);
22         bytes[0] = dis.readShort();
23     }
24     
25     public short getConstantValueIndex() {
26         return bytes[0];
27     }
28
29     public byte[] getBytes() {
30         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
31         DataOutputStream JavaDoc dos = new DataOutputStream JavaDoc(baos);
32
33         try {
34             dos.writeShort(bytes[0]);
35         }
36         catch(IOException JavaDoc ioe) {
37             // Should not ever happen
38
throw new RuntimeException JavaDoc(ioe);
39         }
40
41         return baos.toByteArray();
42     }
43 }
44
45
Popular Tags