1 package alt.jiapi.file; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.DataInputStream ; 5 import java.io.DataOutputStream ; 6 import java.io.IOException ; 7 import java.util.List ; 8 import java.util.LinkedList ; 9 import java.util.Iterator ; 10 11 17 public class InnerClassesAttribute extends Attribute { 18 List classes = new LinkedList (); 19 20 InnerClassesAttribute(short nameIndex, DataInputStream dis) throws IOException { 21 super(nameIndex); 22 23 short count = dis.readShort(); 24 for (int i = 0; i < count; i++) { 25 short inner_class_info_index = dis.readShort(); 26 short outer_class_info_index = dis.readShort(); 27 short inner_name_index = dis.readShort(); 28 short inner_class_access_flags = dis.readShort(); 29 30 classes.add(new InnerClass(inner_class_info_index, 31 outer_class_info_index, 32 inner_name_index, 33 inner_class_access_flags)); 34 } 35 } 36 37 public byte[] getBytes() { 38 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 39 DataOutputStream dos = new DataOutputStream (baos); 40 41 try { 42 dos.writeShort(classes.size()); 43 44 Iterator i = classes.iterator(); 45 while(i.hasNext()) { 46 InnerClass ic = (InnerClass)i.next(); 47 dos.writeShort(ic.getInnerClassInfoIndex()); 48 dos.writeShort(ic.getOuterClassInfoIndex()); 49 dos.writeShort(ic.getInnerNameIndex()); 50 dos.writeShort(ic.getInnerClassAccessFlags()); 51 } 52 } 53 catch(IOException ioe) { 54 throw new RuntimeException (ioe); 56 } 57 58 return baos.toByteArray(); 59 } 60 61 62 public class InnerClass { 63 private short inner_class_info_index; 64 private short outer_class_info_index; 65 private short inner_name_index; 66 private short inner_class_access_flags; 67 68 public InnerClass(short inner_class_info_index, 69 short outer_class_info_index, 70 short inner_name_index, 71 short inner_class_access_flags) { 72 this.inner_class_info_index = inner_class_info_index; 73 this.outer_class_info_index = outer_class_info_index; 74 this.inner_name_index = inner_name_index; 75 this.inner_class_access_flags = inner_class_access_flags; 76 } 77 78 79 public short getInnerClassInfoIndex() { 80 return inner_class_info_index; 81 } 82 public short getOuterClassInfoIndex() { 83 return outer_class_info_index; 84 } 85 public short getInnerNameIndex() { 86 return inner_name_index; 87 } 88 public short getInnerClassAccessFlags() { 89 return inner_class_access_flags; 90 } 91 } 92 } 93 94 | Popular Tags |