1 26 package net.sf.javaguard.classfile; 27 28 import java.io.*; 29 30 31 36 public class ExceptionsAttrInfo extends AttrInfo { 37 38 private int numberOfExceptions; 39 40 private int[] exceptionIndexTable; 41 42 43 44 45 50 protected ExceptionsAttrInfo(ClassFile cf, int attrNameIndex, int attrLength) { 51 super(cf, attrNameIndex, attrLength); 52 } 53 54 55 56 57 60 protected String getAttrName() { 61 return ATTR_Exceptions; 62 } 63 64 65 66 67 71 protected void setNumberOfExceptions(int len) { 72 numberOfExceptions = len; 73 } 74 75 76 80 protected int getNumberOfExceptions() { 81 return numberOfExceptions; 82 } 83 84 85 86 87 91 protected void setExceptionIndexTable(int[] indexTable) { 92 exceptionIndexTable = indexTable; 93 } 94 95 96 100 protected int[] getExceptionIndexTable() { 101 return exceptionIndexTable; 102 } 103 104 105 106 107 111 protected void readInfo(DataInput din) 112 throws IOException { 113 setNumberOfExceptions(din.readUnsignedShort()); 114 int[] indexTable = new int[getNumberOfExceptions()]; 115 for (int i = 0; i < getNumberOfExceptions(); i++) { 116 indexTable[i] = din.readUnsignedShort(); 117 } 118 setExceptionIndexTable(indexTable); 119 } 120 121 122 127 public void writeInfo(DataOutput dout) 128 throws IOException { 129 dout.writeShort(getNumberOfExceptions()); 130 for (int i = 0; i < getNumberOfExceptions(); i++) { 131 dout.writeShort(getExceptionIndexTable()[i]); 132 } 133 } 134 135 136 137 138 142 public void dump(PrintWriter pw, ClassFile cf) { 143 pw.println("Exception table:"); 144 pw.print("Number of exceptions: "); 145 pw.println(getNumberOfExceptions()); 146 for (int i=0; i<getNumberOfExceptions(); i++) { 147 pw.print("Exception index["); 148 pw.print(i); 149 pw.print("]: "); 150 pw.println(getExceptionIndexTable()[i]); 151 } 152 } 153 } 154 | Popular Tags |