KickJava   Java API By Example, From Geeks To Geeks.

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


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.4
16  */

17 public class ExceptionsAttribute extends Attribute {
18     private short[] exceptionIndexTable;
19
20     ExceptionsAttribute(short nameIndex, DataInputStream JavaDoc dis) throws IOException JavaDoc {
21         super(nameIndex);
22
23         short exceptionCount = dis.readShort();
24         exceptionIndexTable = new short[exceptionCount];
25         for (int i = 0; i < exceptionCount; i++) {
26             exceptionIndexTable[i] = dis.readShort();
27         }
28     }
29     
30     short[] getExceptionIndexTable() {
31         return exceptionIndexTable;
32     }
33
34     public String JavaDoc[] getExceptionNames() {
35         String JavaDoc[] eNames = new String JavaDoc[exceptionIndexTable.length];
36         for (int i = 0; i < eNames.length; i++) {
37             eNames[i] = cp.getClassName(exceptionIndexTable[i]).replace('/', '.');
38         }
39
40         return eNames;
41     }
42
43     public byte[] getBytes() {
44         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
45         DataOutputStream JavaDoc dos = new DataOutputStream JavaDoc(baos);
46
47         try {
48             dos.writeShort(exceptionIndexTable.length);
49
50             for (int i = 0; i < exceptionIndexTable.length; i++) {
51                 dos.writeShort(exceptionIndexTable[i]);
52             }
53         }
54         catch(IOException JavaDoc ioe) {
55             // Should not ever happen
56
throw new RuntimeException JavaDoc(ioe);
57         }
58
59         return baos.toByteArray();
60     }
61 }
62
63
Popular Tags