FileDocCategorySizeDatePackage
ConstantString.javaAPI DocJava SE 6 API5288Tue Jun 10 00:22:16 BST 2008com.sun.org.apache.bcel.internal.classfile

ConstantString

public final class ConstantString extends Constant implements ConstantObject
This class is derived from the abstract Constant class and represents a reference to a String object.
version
$Id: ConstantString.java,v 1.1.2.1 2005/07/31 23:46:38 jeffsuttor Exp $
author
M. Dahm
see
Constant

Fields Summary
private int
string_index
Constructors Summary
public ConstantString(ConstantString c)
Initialize from another object.

    this(c.getStringIndex());
  
ConstantString(DataInputStream file)
Initialize instance from file data.

param
file Input stream
throws
IOException

    
    this((int)file.readUnsignedShort());
  
public ConstantString(int string_index)

param
string_index Index of Constant_Utf8 in constant pool

    
    super(Constants.CONSTANT_String);
    this.string_index = string_index;
  
Methods Summary
public voidaccept(com.sun.org.apache.bcel.internal.classfile.Visitor v)
Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.

param
v Visitor object

    v.visitConstantString(this);
  
public final voiddump(java.io.DataOutputStream file)
Dump constant field reference to file stream in binary format.

param
file Output file stream
throws
IOException

    file.writeByte(tag);
    file.writeShort(string_index);
  
public java.lang.StringgetBytes(com.sun.org.apache.bcel.internal.classfile.ConstantPool cp)

return
dereferenced string

    return (String)getConstantValue(cp);
  
public java.lang.ObjectgetConstantValue(com.sun.org.apache.bcel.internal.classfile.ConstantPool cp)

return
String object

    Constant c = cp.getConstant(string_index, Constants.CONSTANT_Utf8);
    return ((ConstantUtf8)c).getBytes();
  
public final intgetStringIndex()

return
Index in constant pool of the string (ConstantUtf8).

 return string_index; 
public final voidsetStringIndex(int string_index)

param
string_index.

    this.string_index = string_index;
  
public final java.lang.StringtoString()

return
String representation.

    return super.toString() + "(string_index = " + string_index + ")";