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 33 public final class ConstantString extends Constant implements ConstantObject { 34 35 private int string_index; 37 38 41 public ConstantString(ConstantString c) { 42 this(c.getStringIndex()); 43 } 44 45 46 52 ConstantString(DataInputStream file) throws IOException { 53 this(file.readUnsignedShort()); 54 } 55 56 57 60 public ConstantString(int string_index) { 61 super(Constants.CONSTANT_String); 62 this.string_index = string_index; 63 } 64 65 66 73 public void accept( Visitor v ) { 74 v.visitConstantString(this); 75 } 76 77 78 84 public final void dump( DataOutputStream file ) throws IOException { 85 file.writeByte(tag); 86 file.writeShort(string_index); 87 } 88 89 90 93 public final int getStringIndex() { 94 return string_index; 95 } 96 97 98 101 public final void setStringIndex( int string_index ) { 102 this.string_index = string_index; 103 } 104 105 106 109 public final String toString() { 110 return super.toString() + "(string_index = " + string_index + ")"; 111 } 112 113 114 116 public Object getConstantValue( ConstantPool cp ) { 117 Constant c = cp.getConstant(string_index, Constants.CONSTANT_Utf8); 118 return ((ConstantUtf8) c).getBytes(); 119 } 120 121 122 124 public String getBytes( ConstantPool cp ) { 125 return (String ) getConstantValue(cp); 126 } 127 } 128 | Popular Tags |