@@ -29,7 +29,7 @@ public static byte[] string2byteArray(CharSequence charSequence2Serialize) throw
2929 }
3030
3131 public static void writeByteArray (byte [] bytes2Write , OutputStream os ) throws IOException {
32- if (bytes2Write == null ) {
32+ if (bytes2Write == null ) {
3333 writeNonNegativeIntegerParameter (0 , os );
3434 } else {
3535 writeNonNegativeIntegerParameter (bytes2Write .length , os );
@@ -40,7 +40,7 @@ public static void writeByteArray(byte[] bytes2Write, OutputStream os) throws IO
4040 public static byte [] readByteArray (InputStream is ) throws IOException , ASAPException {
4141 // read len
4242 int len = readIntegerParameter (is );
43- if (len == 0 ) return new byte [0 ];
43+ if (len == 0 ) return new byte [0 ];
4444
4545 byte [] messageBytes = new byte [len ];
4646 // read encrypted bytes from stream
@@ -50,11 +50,11 @@ public static byte[] readByteArray(InputStream is) throws IOException, ASAPExcep
5050 }
5151
5252 public static void writeByteArray (byte [][] bytes2Dim , OutputStream os ) throws IOException {
53- if (bytes2Dim == null ) {
53+ if (bytes2Dim == null ) {
5454 writeNonNegativeIntegerParameter (0 , os );
5555 } else {
5656 writeNonNegativeIntegerParameter (bytes2Dim .length , os );
57- for (int i = 0 ; i < bytes2Dim .length ; i ++) {
57+ for (int i = 0 ; i < bytes2Dim .length ; i ++) {
5858 ASAPSerialization .writeByteArray (bytes2Dim [i ], os );
5959 }
6060 }
@@ -63,29 +63,30 @@ public static void writeByteArray(byte[][] bytes2Dim, OutputStream os) throws IO
6363 public static byte [][] readByte2DimArray (InputStream is ) throws IOException , ASAPException {
6464 // read len
6565 int len = readIntegerParameter (is );
66- if (len == 0 ) return new byte [0 ][];
66+ if (len == 0 ) return new byte [0 ][];
6767
6868 byte [][] messageBytes = new byte [len ][];
69- for (int i = 0 ; i < len ; i ++) {
69+ for (int i = 0 ; i < len ; i ++) {
7070 messageBytes [i ] = ASAPSerialization .readByteArray (is );
7171 }
7272
7373 return messageBytes ;
7474 }
7575
7676 public static void writeCharSequenceParameter (CharSequence parameter , OutputStream os ) throws IOException {
77- if (parameter == null || parameter .length () < 1 ) return ;
77+ if (parameter == null || parameter .length () < 1 ) return ;
7878 byte [] bytes = parameter .toString ().getBytes ();
7979 writeNonNegativeIntegerParameter (bytes .length , os );
8080 os .write (bytes );
8181 }
8282
8383 public static void writeByteParameter (byte parameter , OutputStream os ) throws IOException {
84- os .write (new byte [] { parameter } );
84+ os .write (new byte []{ parameter });
8585 }
8686
8787 /**
8888 * Return a byte from an int - position starts with 0 at least significant bit
89+ *
8990 * @param source
9091 * @param position
9192 * @return
@@ -101,13 +102,13 @@ public static void writeShortParameter(short shortValue, OutputStream os) throws
101102 short left = (short ) (shortValue & BLANK_RIGHT_SHORT );
102103 left = (short ) (left >> 8 );
103104 short right = (short ) (shortValue & BLANK_LEFT_SHORT );
104- writeByteParameter ( (byte )left , os );
105+ writeByteParameter ((byte ) left , os );
105106 // cut left part
106- writeByteParameter ( (byte )right , os );
107+ writeByteParameter ((byte ) right , os );
107108 }
108109
109110 public static void writeNonNegativeIntegerParameter (int parameter , OutputStream os ) throws IOException {
110- if (parameter < 0 ) return ; // non negative!
111+ if (parameter < 0 ) return ; // non negative!
111112
112113 // Integer == 32 bit == 4 Byte
113114 int left = parameter >> 16 ;
@@ -125,7 +126,7 @@ public static void writeIntegerParameter(int intValue, OutputStream os) throws I
125126 }
126127
127128 public static void writeNonNegativeLongParameter (long longValue , OutputStream os ) throws IOException {
128- if (longValue > -1 ) writeLongParameter (longValue , os );
129+ if (longValue > -1 ) writeLongParameter (longValue , os );
129130 else throw new IOException ("negative value" );
130131 }
131132
@@ -134,19 +135,19 @@ public static void writeLongParameter(long longValue, OutputStream os) throws IO
134135 long left = longValue & BLANK_RIGHT_LONG ;
135136 left = left >> 32 ;
136137 long right = longValue & BLANK_LEFT_LONG ;
137- writeIntegerParameter ((int )left , os );
138- writeIntegerParameter ((int )right , os );
138+ writeIntegerParameter ((int ) left , os );
139+ writeIntegerParameter ((int ) right , os );
139140 }
140141
141142 public static void printBits (long l , int bits ) {
142143 long mask = 1 ;
143- mask = mask << bits - 1 ;
144+ mask = mask << bits - 1 ;
144145 short byteBitCounter = 4 ;
145146 StringBuffer stringBuffer = new StringBuffer ();
146- while (mask != 0 ) {
147- if ((l & mask ) != 0 ) stringBuffer .append ("1" );
147+ while (mask != 0 ) {
148+ if ((l & mask ) != 0 ) stringBuffer .append ("1" );
148149 else stringBuffer .append ("0" );
149- if (--byteBitCounter == 0 ) {
150+ if (--byteBitCounter == 0 ) {
150151 byteBitCounter = 4 ;
151152 stringBuffer .append (" " );
152153 }
@@ -159,12 +160,12 @@ public static String printBitsToString(long l, int bits) {
159160 StringBuilder sb = new StringBuilder ();
160161
161162 long mask = 1 ;
162- mask = mask << bits - 1 ;
163+ mask = mask << bits - 1 ;
163164 short byteBitCounter = 4 ;
164- while (mask != 0 ) {
165- if ((l & mask ) != 0 ) sb .append ("1" );
165+ while (mask != 0 ) {
166+ if ((l & mask ) != 0 ) sb .append ("1" );
166167 else sb .append ("0" );
167- if (--byteBitCounter == 0 ) {
168+ if (--byteBitCounter == 0 ) {
168169 byteBitCounter = 4 ;
169170 sb .append (" " );
170171 }
@@ -177,7 +178,7 @@ public static String printBitsToString(long l, int bits) {
177178
178179 public static String printByteArrayToString (byte [] byteArray ) {
179180 StringBuilder sb = new StringBuilder ();
180- for (int index = byteArray .length - 1 ; index >= 0 ; index --) {
181+ for (int index = byteArray .length - 1 ; index >= 0 ; index --) {
181182 sb .append ("[" );
182183 sb .append (index );
183184 sb .append ("]: " );
@@ -186,18 +187,32 @@ public static String printByteArrayToString(byte[] byteArray) {
186187 return sb .toString ();
187188 }
188189
189- public static String printByteToString (short s ) { return printBitsToString (s , 8 ); }
190- public static String printBitsToString (int i ) { return printBitsToString (i , 16 ); }
190+ public static String printByteToString (short s ) {
191+ return printBitsToString (s , 8 );
192+ }
193+
194+ public static String printBitsToString (int i ) {
195+ return printBitsToString (i , 16 );
196+ }
191197
192198 public static void printByteArray (byte [] byteArray ) {
193- for (int index = byteArray .length - 1 ; index >= 0 ; index --) {
199+ for (int index = byteArray .length - 1 ; index >= 0 ; index --) {
194200 printByte (byteArray [index ]);
195201 }
196202 }
197203
198- public static void printByte (short s ) { printBits (s , 8 ); }
199- public static void printBits (short s ) { printBits (s , 16 ); }
200- public static void printBits (int i ) { printBits (i , 32 ); }
204+ public static void printByte (short s ) {
205+ printBits (s , 8 );
206+ }
207+
208+ public static void printBits (short s ) {
209+ printBits (s , 16 );
210+ }
211+
212+ public static void printBits (int i ) {
213+ printBits (i , 32 );
214+ }
215+
201216 public static void printBits (long l ) {
202217 long left = l & BLANK_RIGHT_LONG ;
203218 left = left >> 32 ;
@@ -213,12 +228,11 @@ public static byte readByteParameter(InputStream is) throws IOException, ASAPExc
213228 public static byte readByte (InputStream is ) throws IOException , ASAPException {
214229 try {
215230 int value = is .read ();
216- if (value < 0 ) {
231+ if (value < 0 ) {
217232 throw new ASAPException ("read -1: no more data in stream" );
218233 }
219234 return (byte ) value ;
220- }
221- catch (IOException e ) {
235+ } catch (IOException e ) {
222236 Log .writeLog (ASAPSerialization .class , "caught IOException during readByte(): "
223237 + e .getClass ().getSimpleName () + ": "
224238 + e .getLocalizedMessage ());
@@ -272,8 +286,8 @@ public static String readCharSequenceParameter(InputStream is) throws IOExceptio
272286 byte [] parameterBytes = null ;
273287 String lenString = null ;
274288// try {
275- length = readIntegerParameter (is );
276- parameterBytes = new byte [length ];
289+ length = readIntegerParameter (is );
290+ parameterBytes = new byte [length ];
277291/*
278292 }
279293 catch(OutOfMemoryError e) {
@@ -288,7 +302,7 @@ public static String readCharSequenceParameter(InputStream is) throws IOExceptio
288302 }
289303
290304 public static void writeCharSequenceSetParameter (Set <CharSequence > charSet , OutputStream os ) throws IOException {
291- if (charSet == null || charSet .size () == 0 ) {
305+ if (charSet == null || charSet .size () == 0 ) {
292306 ASAPSerialization .writeNonNegativeIntegerParameter (0 , os );
293307 return ;
294308 }
@@ -299,7 +313,7 @@ public static void writeCharSequenceSetParameter(Set<CharSequence> charSet, Outp
299313 ASAPSerialization .writeNonNegativeIntegerParameter (charSet .size (), os );
300314
301315 // write entries
302- for (CharSequence entry : charSet ) {
316+ for (CharSequence entry : charSet ) {
303317 ASAPSerialization .writeCharSequenceParameter (entry , os );
304318 }
305319 }
@@ -308,7 +322,7 @@ public static Set<CharSequence> readCharSequenceSetParameter(InputStream is) thr
308322 Set <CharSequence > charSet = new HashSet <>();
309323 int len = ASAPSerialization .readIntegerParameter (is );
310324
311- while (len -- > 0 ) {
325+ while (len -- > 0 ) {
312326 charSet .add (ASAPSerialization .readCharSequenceParameter (is ));
313327 }
314328
@@ -317,11 +331,15 @@ public static Set<CharSequence> readCharSequenceSetParameter(InputStream is) thr
317331
318332 public static ASAPEncounterConnectionType readEncounterConnectionType (InputStream is ) throws IOException , ASAPException {
319333 byte readByte = ASAPSerialization .readByte (is );
320- switch (readByte ) {
321- case 1 : return ASAPEncounterConnectionType .ASAP_HUB ;
322- case 2 : return ASAPEncounterConnectionType .AD_HOC_LAYER_2_NETWORK ;
323- case 3 : return ASAPEncounterConnectionType .ONION_NETWORK ;
324- case 4 : return ASAPEncounterConnectionType .INTERNET ;
334+ switch (readByte ) {
335+ case 1 :
336+ return ASAPEncounterConnectionType .ASAP_HUB ;
337+ case 2 :
338+ return ASAPEncounterConnectionType .AD_HOC_LAYER_2_NETWORK ;
339+ case 3 :
340+ return ASAPEncounterConnectionType .ONION_NETWORK ;
341+ case 4 :
342+ return ASAPEncounterConnectionType .INTERNET ;
325343 default :
326344 Log .writeLogErr (ASAPSerialization .class , "unknown encounter connection type: " + readByte );
327345 }
@@ -330,18 +348,27 @@ public static ASAPEncounterConnectionType readEncounterConnectionType(InputStrea
330348 }
331349
332350 public static void writeEncounterConnectionType (ASAPEncounterConnectionType connectionType , OutputStream os ) throws IOException {
333- switch (connectionType ) {
334- case ASAP_HUB : ASAPSerialization .writeByteParameter ((byte ) 1 , os ); break ;
335- case AD_HOC_LAYER_2_NETWORK : ASAPSerialization .writeByteParameter ((byte ) 2 , os ); break ;
336- case ONION_NETWORK : ASAPSerialization .writeByteParameter ((byte ) 3 , os ); break ;
337- case INTERNET : ASAPSerialization .writeByteParameter ((byte ) 4 , os ); break ;
351+ switch (connectionType ) {
352+ case ASAP_HUB :
353+ ASAPSerialization .writeByteParameter ((byte ) 1 , os );
354+ break ;
355+ case AD_HOC_LAYER_2_NETWORK :
356+ ASAPSerialization .writeByteParameter ((byte ) 2 , os );
357+ break ;
358+ case ONION_NETWORK :
359+ ASAPSerialization .writeByteParameter ((byte ) 3 , os );
360+ break ;
361+ case INTERNET :
362+ ASAPSerialization .writeByteParameter ((byte ) 4 , os );
363+ break ;
338364 case UNKNOWN :
339- default : ASAPSerialization .writeByteParameter ((byte ) 0 , os );
365+ default :
366+ ASAPSerialization .writeByteParameter ((byte ) 0 , os );
340367 }
341368 }
342369
343370 public static void writeBooleanParameter (boolean value , OutputStream os ) throws IOException {
344- if (value ) ASAPSerialization .writeByteParameter ((byte ) 1 , os );
371+ if (value ) ASAPSerialization .writeByteParameter ((byte ) 1 , os );
345372 else ASAPSerialization .writeByteParameter ((byte ) 0 , os );
346373 }
347374
@@ -388,15 +415,15 @@ public static List<ASAPHop> byteArray2ASAPHopList(byte[] bytes) throws IOExcepti
388415 }
389416
390417 public static void writeASAPHopList (List <ASAPHop > asapHopList , OutputStream os ) throws IOException {
391- if (asapHopList == null || asapHopList .isEmpty ()) {
418+ if (asapHopList == null || asapHopList .isEmpty ()) {
392419 // no hops
393420 ASAPSerialization .writeIntegerParameter (0 , os );
394421 return ;
395422 }
396423
397424 // write number of hops
398425 ASAPSerialization .writeIntegerParameter (asapHopList .size (), os );
399- for (ASAPHop asapHop : asapHopList ) {
426+ for (ASAPHop asapHop : asapHopList ) {
400427 ASAPSerialization .writeASAPHop (asapHop , os );
401428 }
402429 }
@@ -405,7 +432,7 @@ public static List<ASAPHop> readASAPHopList(InputStream is) throws IOException,
405432 List <ASAPHop > asapHopList = new ArrayList <>();
406433
407434 int number = ASAPSerialization .readIntegerParameter (is );
408- while (number -- > 0 ) {
435+ while (number -- > 0 ) {
409436 asapHopList .add (ASAPSerialization .readASAPHop (is ));
410437 }
411438
0 commit comments