1 7 package org.gjt.jclasslib.structures.elementvalues; 8 9 import org.gjt.jclasslib.structures.InvalidByteCodeException; 10 11 import java.io.*; 12 13 19 public class ArrayElementValue extends ElementValue { 20 21 public final static String ENTRY_NAME = "ArrayElement"; 22 23 private static final int INITIAL_LENGTH = 2; 24 private ElementValue[] elementValueEntries; 25 26 27 protected ArrayElementValue() { 28 super(ARRAY_TAG); 29 } 30 31 37 public ElementValue[] getElementValueEntries() { 38 return this.elementValueEntries; 39 } 40 41 47 public void setConstValueIndex(ElementValue[] elementValueEntries) { 48 this.elementValueEntries = elementValueEntries; 49 } 50 51 protected int getSpecificLength() { 52 int length = INITIAL_LENGTH; 53 for (int i = 0; i < elementValueEntries.length; i++) { 54 length += elementValueEntries[i].getLength(); 55 } 56 return length; 57 } 58 59 public void read(DataInput in) throws InvalidByteCodeException, IOException { 60 super.read(in); 61 62 int elementValueEntriesLength = in.readUnsignedShort(); 63 elementValueEntries = new ElementValue[elementValueEntriesLength]; 64 for (int i = 0; i < elementValueEntries.length; i++) { 65 elementValueEntries[i] = ElementValue.create(in, classFile); 66 } 67 68 if (debug) debug("read "); 69 } 70 71 public void write(DataOutput out) throws InvalidByteCodeException, IOException { 72 super.write(out); 73 74 int elementValueEntriesLength = getLength(elementValueEntries); 75 76 out.writeShort(elementValueEntriesLength); 77 for (int i = 0; i < elementValueEntriesLength; i++) { 78 elementValueEntries[i].write(out); 79 } 80 81 if (debug) debug("wrote "); 82 } 83 84 protected void debug(String message) { 85 super.debug(message + 86 "ArrayElementValue with " + 87 getLength(elementValueEntries) + " entries"); 88 } 89 90 public String getEntryName() { 91 return ENTRY_NAME; 92 } 93 94 } 95 | Popular Tags |