1 7 8 package org.gjt.jclasslib.structures.attributes; 9 10 import org.gjt.jclasslib.structures.AttributeInfo; 11 import org.gjt.jclasslib.structures.InvalidByteCodeException; 12 13 import java.io.*; 14 15 21 public class ExceptionsAttribute extends AttributeInfo { 22 23 24 public static final String ATTRIBUTE_NAME = "Exceptions"; 25 26 private static final int INITIAL_LENGTH = 2; 27 28 private int[] exceptionIndexTable; 29 30 35 public int[] getExceptionIndexTable() { 36 return exceptionIndexTable; 37 } 38 39 44 public void setExceptionIndexTable(int[] exceptionIndexTable) { 45 this.exceptionIndexTable = exceptionIndexTable; 46 } 47 48 public void read(DataInput in) 49 throws InvalidByteCodeException, IOException { 50 51 int numberOfExceptions = in.readUnsignedShort(); 52 exceptionIndexTable = new int[numberOfExceptions]; 53 for (int i = 0 ; i < numberOfExceptions; i++) { 54 exceptionIndexTable[i] = in.readUnsignedShort(); 55 } 56 57 if (debug) debug("read "); 58 } 59 60 public void write(DataOutput out) 61 throws InvalidByteCodeException, IOException { 62 63 super.write(out); 64 65 int numberOfExceptions = getLength(exceptionIndexTable); 66 67 out.writeShort(numberOfExceptions); 68 for (int i = 0 ; i < numberOfExceptions; i++) { 69 out.writeShort(exceptionIndexTable[i]); 70 } 71 if (debug) debug("wrote "); 72 } 73 74 public int getAttributeLength() { 75 return INITIAL_LENGTH + 2 * getLength(exceptionIndexTable); 76 } 77 78 protected void debug(String message) { 79 super.debug(message + "Exception attribute with " + getLength(exceptionIndexTable) + " exceptions"); 80 } 81 82 } 83 | Popular Tags |