1 17 package org.apache.bcel.classfile; 18 19 import java.io.DataInputStream ; 20 import java.io.DataOutputStream ; 21 import java.io.IOException ; 22 import org.apache.bcel.Constants; 23 24 37 public final class Synthetic extends Attribute { 38 39 private byte[] bytes; 40 41 42 46 public Synthetic(Synthetic c) { 47 this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool()); 48 } 49 50 51 59 public Synthetic(int name_index, int length, byte[] bytes, ConstantPool constant_pool) { 60 super(Constants.ATTR_SYNTHETIC, name_index, length, constant_pool); 61 this.bytes = bytes; 62 } 63 64 65 73 Synthetic(int name_index, int length, DataInputStream file, ConstantPool constant_pool) 74 throws IOException { 75 this(name_index, length, (byte[]) null, constant_pool); 76 if (length > 0) { 77 bytes = new byte[length]; 78 file.readFully(bytes); 79 System.err.println("Synthetic attribute with length > 0"); 80 } 81 } 82 83 84 91 public void accept( Visitor v ) { 92 v.visitSynthetic(this); 93 } 94 95 96 102 public final void dump( DataOutputStream file ) throws IOException { 103 super.dump(file); 104 if (length > 0) { 105 file.write(bytes, 0, length); 106 } 107 } 108 109 110 113 public final byte[] getBytes() { 114 return bytes; 115 } 116 117 118 121 public final void setBytes( byte[] bytes ) { 122 this.bytes = bytes; 123 } 124 125 126 129 public final String toString() { 130 StringBuffer buf = new StringBuffer ("Synthetic"); 131 if (length > 0) { 132 buf.append(" ").append(Utility.toHexString(bytes)); 133 } 134 return buf.toString(); 135 } 136 137 138 141 public Attribute copy( ConstantPool _constant_pool ) { 142 Synthetic c = (Synthetic) clone(); 143 if (bytes != null) { 144 c.bytes = new byte[bytes.length]; 145 System.arraycopy(bytes, 0, c.bytes, 0, bytes.length); 146 } 147 c.constant_pool = _constant_pool; 148 return c; 149 } 150 } 151 | Popular Tags |