1 16 17 package org.cojen.classfile.attribute; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 import java.io.DataInput ; 22 import java.io.DataOutput ; 23 import java.io.IOException ; 24 import org.cojen.classfile.Attribute; 25 import org.cojen.classfile.ConstantPool; 26 import org.cojen.classfile.constant.ConstantClassInfo; 27 28 34 public class ExceptionsAttr extends Attribute { 35 36 private List mExceptions = new ArrayList (2); 37 38 public ExceptionsAttr(ConstantPool cp) { 39 super(cp, EXCEPTIONS); 40 } 41 42 public ExceptionsAttr(ConstantPool cp, String name) { 43 super(cp, name); 44 } 45 46 public ExceptionsAttr(ConstantPool cp, String name, int length, DataInput din) 47 throws IOException 48 { 49 super(cp, name); 50 51 int size = din.readUnsignedShort(); 52 length -= 2; 53 54 for (int i=0; i<size; i++) { 55 int index = din.readUnsignedShort(); 56 length -= 2; 57 ConstantClassInfo info = (ConstantClassInfo)cp.getConstant(index); 58 addException(info); 59 } 60 61 if (length > 0) { 62 din.skipBytes(length); 63 } 64 } 65 66 public ConstantClassInfo[] getExceptions() { 67 ConstantClassInfo[] copy = new ConstantClassInfo[mExceptions.size()]; 68 return (ConstantClassInfo[])mExceptions.toArray(copy); 69 } 70 71 public void addException(ConstantClassInfo type) { 72 mExceptions.add(type); 73 } 74 75 public int getLength() { 76 return 2 + 2 * mExceptions.size(); 77 } 78 79 public void writeDataTo(DataOutput dout) throws IOException { 80 int size = mExceptions.size(); 81 dout.writeShort(size); 82 for (int i=0; i<size; i++) { 83 ConstantClassInfo info = (ConstantClassInfo)mExceptions.get(i); 84 dout.writeShort(info.getIndex()); 85 } 86 } 87 } 88 | Popular Tags |