@@ -67,6 +67,13 @@ public static void writeCharSequenceParameter(CharSequence parameter, OutputStre
6767 byte [] bytes = parameter .toString ().getBytes ();
6868 writeNonNegativeIntegerParameter (bytes .length , os );
6969 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+ */
7077 }
7178
7279 public static void writeByteParameter (byte parameter , OutputStream os ) throws IOException {
@@ -143,6 +150,37 @@ public static void printBits(long l, int bits) {
143150 System .out .print (" " );
144151 }
145152
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+
146184 public static void printByteArray (byte [] byteArray ) {
147185 for (int index = byteArray .length - 1 ; index >= 0 ; index --) {
148186 printByte (byteArray [index ]);
@@ -186,8 +224,10 @@ public static short readShortParameter(InputStream is) throws IOException, ASAPE
186224 }
187225
188226 public static int readIntegerParameter (InputStream is ) throws IOException , ASAPException {
189- int value = readShortParameter (is );
227+ int value = 0 ;
228+ value = readShortParameter (is );
190229 value = value << 16 ;
230+
191231 value = value & BLANK_RIGHT_INTEGER ;
192232
193233 int right = readShortParameter (is );
@@ -218,11 +258,33 @@ public static long readLongParameter(InputStream is) throws IOException, ASAPExc
218258 }
219259
220260 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+ */
223279
224280 is .read (parameterBytes );
225281
282+ /*
283+ String readBytesString = printByteArrayToString(parameterBytes);
284+ String log = "readCharSequenceParameter\nlen: " + lenString + "\nbytes: " + readBytesString;
285+ System.out.println(log);
286+ */
287+
226288 return new String (parameterBytes );
227289 }
228290
0 commit comments