Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ConstantUtf8.java

00001 package de.fub.bytecode.classfile;
00002 
00003 import  de.fub.bytecode.Constants;
00004 import  java.io.*;
00005 
00006 /** 
00007  * This class is derived from the abstract 
00008  * <A HREF="de.fub.bytecode.classfile.Constant.html">Constant</A> class 
00009  * and represents a reference to a Utf8 encoded string.
00010  *
00011  * @version $Id: ConstantUtf8.java,v 1.1.1.1 2002/01/24 03:44:00 pserver Exp $
00012  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00013  * @see     Constant
00014  */
00015 public final class ConstantUtf8 extends Constant {
00016   private String bytes;
00017   
00018   /**
00019    * Initialize from another object.
00020    */
00021   public ConstantUtf8(ConstantUtf8 c) {
00022     this(c.getBytes());
00023   }  
00024   /**
00025    * Initialize instance from file data.
00026    *
00027    * @param file Input stream
00028    * @throw IOException
00029    */
00030   ConstantUtf8(DataInputStream file) throws IOException
00031   {    
00032     super(CONSTANT_Utf8);
00033 
00034     bytes = file.readUTF();
00035   }  
00036   /**
00037    * @param bytes Data
00038    */
00039   public ConstantUtf8(String bytes)
00040   {
00041     super(CONSTANT_Utf8);
00042     this.bytes  = bytes;
00043   }  
00044   /**
00045    * Called by objects that are traversing the nodes of the tree implicitely
00046    * defined by the contents of a Java class. I.e., the hierarchy of methods,
00047    * fields, attributes, etc. spawns a tree of objects.
00048    *
00049    * @param v Visitor object
00050    */
00051   public void accept(Visitor v) {
00052     v.visitConstantUtf8(this);
00053   }  
00054   /**
00055    * Dump String in Utf8 format to file stream.
00056    *
00057    * @param file Output file stream
00058    * @throw IOException
00059    */ 
00060   public final void dump(DataOutputStream file) throws IOException
00061   {
00062     file.writeByte(tag);
00063     file.writeUTF(bytes);
00064   }  
00065   /**
00066    * @return Data converted to string.
00067    */  
00068   public final String getBytes() { return bytes; }  
00069   /**
00070    * @param bytes.
00071    */
00072   public final void setBytes(String bytes) {
00073     this.bytes = bytes;
00074   }  
00075   /**
00076    * @return String representation
00077    */
00078   public final String toString()
00079   {
00080     return super.toString() + "(\"" + Utility.replace(bytes, "\n", "\\n") + "\")";
00081   }  
00082 }

Generated at Thu Feb 7 06:43:05 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001