1 package com.sun.org.apache.bcel.internal.classfile; 2 3 56 57 import com.sun.org.apache.bcel.internal.Constants; 58 import java.io.*; 59 60 69 public final class ConstantString extends Constant implements ConstantObject { 70 private int string_index; 72 75 public ConstantString(ConstantString c) { 76 this(c.getStringIndex()); 77 } 78 84 ConstantString(DataInputStream file) throws IOException 85 { 86 this((int)file.readUnsignedShort()); 87 } 88 91 public ConstantString(int string_index) 92 { 93 super(Constants.CONSTANT_String); 94 this.string_index = string_index; 95 } 96 103 public void accept(Visitor v) { 104 v.visitConstantString(this); 105 } 106 112 public final void dump(DataOutputStream file) throws IOException 113 { 114 file.writeByte(tag); 115 file.writeShort(string_index); 116 } 117 120 public final int getStringIndex() { return string_index; } 121 124 public final void setStringIndex(int string_index) { 125 this.string_index = string_index; 126 } 127 130 public final String toString() 131 { 132 return super.toString() + "(string_index = " + string_index + ")"; 133 } 134 135 137 public Object getConstantValue(ConstantPool cp) { 138 Constant c = cp.getConstant(string_index, Constants.CONSTANT_Utf8); 139 return ((ConstantUtf8)c).getBytes(); 140 } 141 142 144 public String getBytes(ConstantPool cp) { 145 return (String )getConstantValue(cp); 146 } 147 } 148 | Popular Tags |