package org.apache.bcel.classfile; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import org.apache.bcel.Constants; /** * * @author dorina * */ public class ExternalMethodsAttribute extends Attribute{ /** * */ private static final long serialVersionUID = -8851110891350869681L; byte []externalMethods; public ExternalMethodsAttribute(int name_index, int length, byte[] externalMethods, ConstantPool cp) { super(Constants.ATTR_EXTERNAL_METHODS, name_index,length, cp); this.externalMethods = externalMethods; } public ExternalMethodsAttribute(int name_index, int length, DataInputStream str, ConstantPool cp) throws IOException { this(name_index, length, (byte [])null, cp); if( length > 0) { externalMethods = new byte[length]; for(int i = 0; i < length; i++) { externalMethods[i] = str.readByte(); } } } /* (non-Javadoc) * @see org.apache.bcel.classfile.Attribute#accept(org.apache.bcel.classfile.Visitor) */ public void accept(Visitor v) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see org.apache.bcel.classfile.Attribute#copy(org.apache.bcel.classfile.ConstantPool) */ public Attribute copy(ConstantPool constant_pool) { ExternalMethodsAttribute copy = (ExternalMethodsAttribute)clone(); System.arraycopy(externalMethods,0,copy.externalMethods,0,externalMethods.length); return copy; } public final void dump(DataOutputStream file) throws IOException { super.dump(file); for(int i = 0; i < externalMethods.length; i++) { file.writeByte(externalMethods[i]); } } /* private int index; public String toString() { for(int ll = 0 ; ll < this.proof.length; ll++) System.out.print(proof[ll]+" "); System.out.println(""); StringBuffer buf = new StringBuffer("ProofAttribute("); index = 0; //read codification byte codification = proof[index++]; buf.append("codification = "+codification+", "); //System.out.println("codification = "+codification); //read proof_table_length int proof_length = SignatureConstants.readInt(proof, index, SignatureConstants.LABEL_BYTECODE_SIZE); index += SignatureConstants.LABEL_BYTECODE_SIZE; buf.append("no of proofs = "+proof_length+", "); //System.out.println("no of proofs = "+proof_length+", "); //read proof_table for(int i=0; i < proof_length; i++) { buf.append("\n[ "); //read label of bytecode int label = SignatureConstants.readInt(proof, index, SignatureConstants.LABEL_BYTECODE_SIZE); index += SignatureConstants.LABEL_BYTECODE_SIZE; buf.append(" label = "+label); //System.out.println("label = "+label); //read stack buf.append(" Stack "+readMultiObjectsTable(codification)); //read local_variables buf.append(" LocalVariables "+readMultiObjectsTable(codification)); //read link_table byte[] tmp = new byte[proof.length-index]; System.arraycopy(proof, index, tmp, 0, proof.length-index); buf.append(LinkAttribute.print(" LinkTable ", tmp)); index += LinkAttribute.getLength(tmp); //LinkAttribute la = new LinkAttribute() buf.append(" ]"); } buf.append(')'); return buf.toString(); } private String readMultiObjectsTable(byte codification) { StringBuffer buf = new StringBuffer("["); //read number of multiObjects int size = SignatureConstants.readInt(proof, index, SignatureConstants.TOTAL_LENGTH_SIZE); index += SignatureConstants.TOTAL_LENGTH_SIZE; //System.out.println("multiobject size = "+size); for(int j = 0; j < size; j++) { //read size of multiobject int mo_size = SignatureConstants.readInt(proof, index, SignatureConstants.MULTIOBJECT_LENGTH_SIZE); index += SignatureConstants.MULTIOBJECT_LENGTH_SIZE; //System.out.println("--mo["+j+"] size = "+mo_size); buf.append("("); for(int k = 0; k < mo_size; k++) { //read jvmtype int jvmtype = SignatureConstants.readInt(proof, index, 1); index ++; int part; if(codification == SignatureConstants.CODIF_6B) { part = jvmtype & 0x03; jvmtype = jvmtype >> 2; } else { part = SignatureConstants.readInt(proof, index, 1); index ++; } buf.append(jvmtype+":"+part); if(k < mo_size-1) buf.append(", "); } buf.append(")"); if(j < size-1) buf.append(", "); } buf.append("]"); return buf.toString(); } */ }