1 52 53 package com.go.trove.classfile; 54 55 import java.util.*; 56 import java.io.*; 57 58 66 class ExceptionsAttr extends Attribute { 67 private List mExceptions = new ArrayList(2); 68 69 public ExceptionsAttr(ConstantPool cp) { 70 super(cp, EXCEPTIONS); 71 } 72 73 public String [] getExceptions() { 74 int size = mExceptions.size(); 75 String [] names = new String [size]; 76 77 for (int i=0; i<size; i++) { 78 names[i] = ((ConstantClassInfo)mExceptions.get(i)).getClassName(); 79 } 80 81 return names; 82 } 83 84 public void addException(ConstantClassInfo type) { 85 mExceptions.add(type); 86 } 87 88 public int getLength() { 89 return 2 + 2 * mExceptions.size(); 90 } 91 92 public void writeDataTo(DataOutput dout) throws IOException { 93 int size = mExceptions.size(); 94 dout.writeShort(size); 95 for (int i=0; i<size; i++) { 96 ConstantClassInfo info = (ConstantClassInfo)mExceptions.get(i); 97 dout.writeShort(info.getIndex()); 98 } 99 } 100 101 static Attribute define(ConstantPool cp, 102 String name, 103 int length, 104 DataInput din) throws IOException { 105 106 ExceptionsAttr attr = new ExceptionsAttr(cp); 107 108 int size = din.readUnsignedShort(); 109 length -= 2; 110 111 for (int i=0; i<size; i++) { 112 int index = din.readUnsignedShort(); 113 length -= 2; 114 ConstantClassInfo info = (ConstantClassInfo)cp.getConstant(index); 115 attr.addException(info); 116 } 117 118 if (length > 0) { 119 din.skipBytes(length); 120 } 121 122 return attr; 123 } 124 } 125 | Popular Tags |