KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > constants > ConstantUtf8Info


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.structures.constants;
9
10 import org.gjt.jclasslib.structures.CPInfo;
11 import org.gjt.jclasslib.structures.InvalidByteCodeException;
12
13 import java.io.*;
14
15 /**
16  * Describes a <tt>CONSTANT_Utf8_info</tt> constant pool data structure.
17  *
18  * @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
19  * @version $Revision: 1.7 $ $Date: 2004/12/28 13:04:32 $
20  */

21 public class ConstantUtf8Info extends CPInfo {
22
23     private String JavaDoc string;
24
25     public byte getTag() {
26         return CONSTANT_UTF8;
27     }
28
29     public String JavaDoc getTagVerbose() {
30         return CONSTANT_UTF8_VERBOSE;
31     }
32
33     public String JavaDoc getVerbose() throws InvalidByteCodeException {
34         return string;
35     }
36
37     /**
38      * Get the byte array of the string in this entry.
39      *
40      * @return the array
41      */

42     public byte[] getBytes() {
43         return string.getBytes();
44     }
45
46     /**
47      * Get the string in this entry.
48      *
49      * @return the string
50      */

51     public String JavaDoc getString() {
52         return string;
53     }
54
55     /**
56      * Set the byte array of the string in this entry.
57      *
58      * @param bytes the array
59      * @deprecated use <tt>setString</tt> instead
60      */

61     public void setBytes(byte[] bytes) {
62         string = new String JavaDoc(bytes);
63     }
64
65     /**
66      * Set the string in this entry.
67      *
68      * @param string the string
69      */

70     public void setString(String JavaDoc string) {
71         this.string = string;
72     }
73
74     public void read(DataInput in)
75             throws InvalidByteCodeException, IOException {
76
77         string = in.readUTF();
78
79         if (debug) debug("read ");
80     }
81
82     public void write(DataOutput out)
83             throws InvalidByteCodeException, IOException {
84
85         out.writeByte(CONSTANT_UTF8);
86         out.writeUTF(string);
87         if (debug) debug("wrote ");
88     }
89
90     protected void debug(String JavaDoc message) {
91         super.debug(message + getTagVerbose() + " with length " + string.length() +
92                 " (\"" + string + "\")");
93     }
94
95     public boolean equals(Object JavaDoc object) {
96         if (!(object instanceof ConstantUtf8Info)) {
97             return false;
98         }
99         ConstantUtf8Info constantUtf8Info = (ConstantUtf8Info)object;
100         return super.equals(object) && constantUtf8Info.string.equals(string);
101     }
102
103     public int hashCode() {
104         return super.hashCode() ^ string.hashCode();
105     }
106
107
108 }
109
Popular Tags