1 30 31 44 package jbet; 45 import java.io.*; 46 47 class CpString extends CpEntry { 48 int stringIndex = -1; String str; 51 53 59 CpString(int i, CPInterface cp) { 60 super(i, CPInterface.CONSTANT_String, cp); 61 } 62 63 64 69 CpString(CPInterface cp, String s) { 70 super(cp.poolCount(), CPInterface.CONSTANT_String, cp); 71 str = s; 72 } 73 74 String string() { return str; }; 75 76 void setup() throws ClassFileException { 77 if (str == null) 78 str = constantPool.cpUtf8At( stringIndex ).string; 79 } 80 81 public String toString() { 82 return "\"" + Util.quoteString(string()) + "\"" ; 83 } 84 85 public boolean equals (Object o) { 86 return (o instanceof CpString) && ((CpString)o).str.equals(str); 87 } 88 89 public int hashCode () { 90 return str.hashCode() + 2; 91 } 92 93 void write(DataOutputStream dataOut) throws IOException { 94 dataOut.writeByte(tag); 95 dataOut.writeShort(stringIndex); 96 } 97 98 } 99 | Popular Tags |