File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
src/com/codebutler/android_websockets Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 33
33
import android .util .Log ;
34
34
35
35
import java .io .*;
36
- import java .math .BigInteger ;
37
36
import java .util .Arrays ;
38
37
import java .util .List ;
39
38
@@ -327,7 +326,7 @@ private byte[] decode(String string) {
327
326
}
328
327
329
328
private int getInteger (byte [] bytes ) throws ProtocolError {
330
- long i = new BigInteger (bytes ). longValue ( );
329
+ long i = byteArrayToLong (bytes , 0 , bytes . length );
331
330
if (i < 0 || i > Integer .MAX_VALUE ) {
332
331
throw new ProtocolError ("Bad integer: " + i );
333
332
}
@@ -344,6 +343,18 @@ public ProtocolError(String detailMessage) {
344
343
}
345
344
}
346
345
346
+ private static long byteArrayToLong (byte [] b , int offset , int length ) {
347
+ if (b .length < length )
348
+ throw new IllegalArgumentException ("length must be less than or equal to b.length" );
349
+
350
+ long value = 0 ;
351
+ for (int i = 0 ; i < length ; i ++) {
352
+ int shift = (length - 1 - i ) * 8 ;
353
+ value += (b [i + offset ] & 0x000000FF ) << shift ;
354
+ }
355
+ return value ;
356
+ }
357
+
347
358
public static class HappyDataInputStream extends DataInputStream {
348
359
public HappyDataInputStream (InputStream in ) {
349
360
super (in );
You can’t perform that action at this time.
0 commit comments