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 InnerClassesAttribute extends AttributeInfo { 22 23 24 public static final String ATTRIBUTE_NAME = "InnerClasses"; 25 26 private static final int INITIAL_LENGTH = 2; 27 28 private InnerClassesEntry[] classes; 29 30 35 public InnerClassesEntry[] getClasses() { 36 return classes; 37 } 38 39 44 public void setClasses(InnerClassesEntry[] classes) { 45 this.classes = classes; 46 } 47 48 public void read(DataInput in) 49 throws InvalidByteCodeException, IOException { 50 51 int numberOfClasses = in.readUnsignedShort(); 52 classes = new InnerClassesEntry[numberOfClasses]; 53 54 for (int i = 0; i < numberOfClasses; i++) { 55 classes[i] = InnerClassesEntry.create(in, classFile); 56 } 57 58 if (debug) debug("read "); 59 } 60 61 public void write(DataOutput out) 62 throws InvalidByteCodeException, IOException { 63 64 super.write(out); 65 66 int numberOfClasses = getLength(classes); 67 68 out.writeShort(numberOfClasses); 69 for (int i = 0 ; i < numberOfClasses; i++) { 70 classes[i].write(out); 71 } 72 if (debug) debug("wrote "); 73 } 74 75 public int getAttributeLength() { 76 return INITIAL_LENGTH + getLength(classes) * InnerClassesEntry.LENGTH; 77 } 78 79 protected void debug(String message) { 80 super.debug(message + "InnerClasses attribute with " + getLength(classes) + " classes"); 81 } 82 83 } 84 | Popular Tags |