@@ -67,6 +67,13 @@ public static void writeCharSequenceParameter(CharSequence parameter, OutputStre
67
67
byte [] bytes = parameter .toString ().getBytes ();
68
68
writeNonNegativeIntegerParameter (bytes .length , os );
69
69
os .write (bytes );
70
+
71
+ /*
72
+ String lenString = printBitsToString(bytes.length);
73
+ String readBytesString = printByteArrayToString(bytes);
74
+ String log = "writeCharSequenceParameter\nlen: " + lenString + "\nbytes: " + readBytesString;
75
+ System.out.println(log);
76
+ */
70
77
}
71
78
72
79
public static void writeByteParameter (byte parameter , OutputStream os ) throws IOException {
@@ -143,6 +150,37 @@ public static void printBits(long l, int bits) {
143
150
System .out .print (" " );
144
151
}
145
152
153
+ public static String printBitsToString (long l , int bits ) {
154
+ StringBuilder sb = new StringBuilder ();
155
+
156
+ long mask = 1 ;
157
+ mask = mask << bits -1 ;
158
+ short byteBitCounter = 4 ;
159
+ while (mask != 0 ) {
160
+ if ((l & mask ) != 0 ) sb .append ("1" );
161
+ else sb .append ("0" );
162
+ if (--byteBitCounter == 0 ) {
163
+ byteBitCounter = 4 ;
164
+ sb .append (" " );
165
+ }
166
+ mask = mask >> 1 ;
167
+ }
168
+ sb .append (" " );
169
+
170
+ return sb .toString ();
171
+ }
172
+
173
+ public static String printByteArrayToString (byte [] byteArray ) {
174
+ StringBuilder sb = new StringBuilder ();
175
+ for (int index = byteArray .length - 1 ; index >= 0 ; index --) {
176
+ sb .append (printByteToString (byteArray [index ]));
177
+ }
178
+ return sb .toString ();
179
+ }
180
+
181
+ public static String printByteToString (short s ) { return printBitsToString (s , 8 ); }
182
+ public static String printBitsToString (int i ) { return printBitsToString (i , 16 ); }
183
+
146
184
public static void printByteArray (byte [] byteArray ) {
147
185
for (int index = byteArray .length - 1 ; index >= 0 ; index --) {
148
186
printByte (byteArray [index ]);
@@ -186,8 +224,10 @@ public static short readShortParameter(InputStream is) throws IOException, ASAPE
186
224
}
187
225
188
226
public static int readIntegerParameter (InputStream is ) throws IOException , ASAPException {
189
- int value = readShortParameter (is );
227
+ int value = 0 ;
228
+ value = readShortParameter (is );
190
229
value = value << 16 ;
230
+
191
231
value = value & BLANK_RIGHT_INTEGER ;
192
232
193
233
int right = readShortParameter (is );
@@ -218,11 +258,33 @@ public static long readLongParameter(InputStream is) throws IOException, ASAPExc
218
258
}
219
259
220
260
public static String readCharSequenceParameter (InputStream is ) throws IOException , ASAPException {
221
- int length = readIntegerParameter (is );
222
- byte [] parameterBytes = new byte [length ];
261
+ int length = 0 ;
262
+ byte [] parameterBytes = null ;
263
+ String lenString = null ;
264
+ // try {
265
+ length = readIntegerParameter (is );
266
+ /*
267
+ lenString = printBitsToString(length);
268
+ System.out.println("readCharSequenceParameter length = " + lenString);
269
+
270
+ */
271
+ parameterBytes = new byte [length ];
272
+ /*
273
+ }
274
+ catch(OutOfMemoryError e) {
275
+ int i = 42;
276
+ throw new ASAPException(e);
277
+ }
278
+ */
223
279
224
280
is .read (parameterBytes );
225
281
282
+ /*
283
+ String readBytesString = printByteArrayToString(parameterBytes);
284
+ String log = "readCharSequenceParameter\nlen: " + lenString + "\nbytes: " + readBytesString;
285
+ System.out.println(log);
286
+ */
287
+
226
288
return new String (parameterBytes );
227
289
}
228
290
0 commit comments