1 ackage jconst;
16
17 import java.io.*;
18 import util.*;
19
20 blic class constUtf8 extends constBase {
36 private String str = null;
37
38 public void read( DataInputStream dStream ) {
39 StringBuffer strBuf;
40 int len, charCnt;
41 byte one_byte;
42 char one_char;
43
44 one_char = '\u0000';
45 len = readU2( dStream );
46 strBuf = new StringBuffer();
47 charCnt = 0;
48 while (charCnt < len) {
49 one_byte = (byte)readU1( dStream );
50 charCnt++;
51 if ((one_byte >> 7) == 1) {
52 short tmp;
53
54 tmp = (short)(one_byte & 0x3f); one_byte = (byte)readU1( dStream );
58 charCnt++;
59 tmp = (short)(tmp | ((one_byte & 0x3f) << 6));
60 if ((one_byte >> 6) == 0x2) {
61 one_byte = (byte)readU1( dStream );
63 charCnt++;
64 one_byte = (byte)(one_byte & 0xf);
65 tmp = (short)(tmp | (one_byte << 12));
66 }
67 one_char = (char)tmp;
68 }
69 else {
70 one_char = (char)one_byte;
71 }
72 strBuf.append(one_char);
73 } str = strBuf.toString();
75 }
77
78
84 public String toAsciiString() {
85 String retStr = null;
86
87 if (str != null) {
88 StringBuffer strbuf = new StringBuffer();
89 int len = str.length();
90 char ch;
91
92 for (int i = 0; i < len; i++) {
93 ch = str.charAt(i);
96 if (ch >= ' ' && ch <= '~')
97 strbuf.append( ch );
98 else {
99 String tmp;
100
101 tmp = null;
102 if (ch == '\b')
103 tmp = "\\b";
104 else if (ch == '\t')
105 tmp = "\\t";
106 else if (ch == '\n')
107 tmp = "\\n";
108 else if (ch == '\f')
109 tmp = "\\f";
110 else if (ch == '\r')
111 tmp = "\\r";
112 else
113 tmp = "\\u" + Integer.toHexString( (int)ch );
114 strbuf.append( tmp );
115 }
116 } retStr = strbuf.toString();
118 }
119 return retStr;
120 }
122
123 public void pr() {
130 System.out.print( toAsciiString() );
131 }
133
134 public void pr_data() {
135 int len = str.length();
136
137 System.out.println("end offset = " + getBytesRead() );
138 System.out.println( str );
139 for (int i = 0; i < str.length(); i++) {
140 System.out.print( Integer.toHexString( (int)str.charAt(i) ) + " " );
141 }
142 System.out.println();
143 }
145
146
149 public String getString() {
150 return str;
151 }
152
153
154
157 public String getPrintableString() {
158 return toAsciiString();
159 }
160
161 }