Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/chaoswg/xtc4y/classdesc/UTF8CPEntry.java


1   //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/UTF8CPEntry.java,v 1.1.1.1 2003/08/07 13:40:29 toggm Exp $
2   /******************************************************************************
3    * XTC4y - eXtreme Testing Collection 4 you                                   *
4    * -------------------------------------------------------------------------- *
5    * URL: http://www.chaoswg.com/xtc4y                                          *
6    * Author: Mike Toggweiler (2.dog@gmx.ch)                                     *
7    *                                                                            *
8    * Last Updated: $Date: 2003/08/07 13:40:29 $, by $Author: toggm $            *
9    * Version: $Revision: 1.1.1.1 $                                                  *
10   * -------------------------------------------------------------------------- *
11   * COPYRIGHT:   (c) 2003 by Mike Toggweiler                                   *
12   *                                                                            *
13   * This program is free software; you can redistribute it and/or modify       *
14   * it under the terms of the GNU General Public License as published by       *
15   * the Free Software Foundation; either version 2 of the License, or          *
16   * (at your option) any later version.                                        *
17   *****************************************************************************/
18  package com.chaoswg.xtc4y.classdesc;
19  
20  import java.io.DataInputStream;
21  import java.io.DataOutputStream;
22  import java.io.IOException;
23  
24  /**
25   * this class represent a UTF8 constant pool entry
26   * @author Mike Toggweiler
27   **/
28  public final class UTF8CPEntry extends ConstantPoolEntry {
29      /**
30       * The tag identifying a UTF8 cp entry
31       **/
32      public static final byte TAG = 1;
33      private String string;
34  
35      /**
36       * Creates a new UTF8 contantpool entry and initalizes it from a 
37       * DataInputStream
38       * @param dis the DataInputStream to read from
39       **/
40      protected UTF8CPEntry(DataInputStream dis) throws IOException {  
41    super(TAG);
42    //length
43    int length = dis.readUnsignedShort();  
44    ByteContainer bContainer = new ByteContainer();
45    //bytes[length]
46    for (int i=0; i<length; ++i) {
47        //byte
48        bContainer.addByte((byte)dis.readUnsignedByte());
49    }
50  
51    string = new String(bContainer.getByteArray());
52      }    
53  
54      /**
55       * Resolve the internal stored indices thorugh the Constantpool
56       * @param cp the constantpool to resolve indices
57       **/
58      protected void resolve(ConstantPool cp) {
59      }
60  
61      /**
62       * Create a new UTF8 constant pool entry with a given string
63       * @param string the utf8 string
64       **/
65      public UTF8CPEntry(String string) {
66    super(TAG);
67    this.string = string;
68      }
69  
70      /**
71       * Write the type specific constant pool entry information onto a 
72       * DataOutputStream
73       * @param dos the DataOutputStream to write on     
74       * @param cp the constantpool entry used to register names
75       **/
76      protected void writeCPEntry(DataOutputStream dos, ConstantPool cp) 
77    throws IOException {
78    dos.writeUTF(string);
79      }
80  
81      /**
82       * @return a String representing the UTF8 bytes
83       **/
84      public String getString() {
85    return string;
86      }
87  
88      /**
89       * Checks if another UTF8CPEntry is equal to this. 
90       **/
91      public boolean equals(Object obj) {
92    if (!(obj instanceof UTF8CPEntry)) {
93        return false;
94    }
95    UTF8CPEntry other = (UTF8CPEntry)obj;  
96    return (this.string == null && other.string == null || 
97      this.string != null && this.string.equals(other.string));
98      }
99  
100     /**
101      * print in a readable way
102      **/
103     public String toString() {
104   return getClass().getName()+":"+hashCode()+":"+string;
105     }
106 }