01: /* ===========================================================================
02: * $RCSfile: ExceptionsAttrInfo.java,v $
03: * ===========================================================================
04: *
05: * RetroGuard -- an obfuscation package for Java classfiles.
06: *
07: * Copyright (c) 1998-2006 Mark Welsh (markw@retrologic.com)
08: *
09: * This program can be redistributed and/or modified under the terms of the
10: * Version 2 of the GNU General Public License as published by the Free
11: * Software Foundation.
12: *
13: * This program is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: */
19:
20: package COM.rl.obf.classfile;
21:
22: import java.io.*;
23: import java.util.*;
24:
25: /**
26: * Representation of an attribute.
27: *
28: * @author Mark Welsh
29: */
30: public class ExceptionsAttrInfo extends AttrInfo {
31: // Constants -------------------------------------------------------------
32:
33: // Fields ----------------------------------------------------------------
34: private int u2numberOfExceptions;
35: private int[] u2exceptionIndexTable;
36:
37: // Class Methods ---------------------------------------------------------
38:
39: // Instance Methods ------------------------------------------------------
40: protected ExceptionsAttrInfo(ClassFile cf, int attrNameIndex,
41: int attrLength) {
42: super (cf, attrNameIndex, attrLength);
43: }
44:
45: /** Return the String name of the attribute; over-ride this in sub-classes. */
46: protected String getAttrName() throws Exception {
47: return ATTR_Exceptions;
48: }
49:
50: /** Return the number of exception class indices. */
51: public int count() {
52: return u2exceptionIndexTable.length;
53: }
54:
55: /** Return the i'th exception class indices. */
56: public int getIndex(int i) {
57: return u2exceptionIndexTable[i];
58: }
59:
60: /** Read the data following the header. */
61: protected void readInfo(DataInput din) throws Exception {
62: u2numberOfExceptions = din.readUnsignedShort();
63: u2exceptionIndexTable = new int[u2numberOfExceptions];
64: for (int i = 0; i < u2numberOfExceptions; i++) {
65: u2exceptionIndexTable[i] = din.readUnsignedShort();
66: }
67: }
68:
69: /** Export data following the header to a DataOutput stream. */
70: public void writeInfo(DataOutput dout) throws Exception {
71: dout.writeShort(u2numberOfExceptions);
72: for (int i = 0; i < u2numberOfExceptions; i++) {
73: dout.writeShort(u2exceptionIndexTable[i]);
74: }
75: }
76: }
|