|
@@ -1,6 +1,7 @@
|
|
|
package com.its.app.utils;
|
|
|
|
|
|
-import java.text.ParseException;
|
|
|
+import java.nio.ByteBuffer;
|
|
|
+import java.nio.ByteOrder;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.Date;
|
|
@@ -195,4 +196,30 @@ public final class SysUtils
|
|
|
|
|
|
return sb.toString();
|
|
|
}
|
|
|
+
|
|
|
+ public static int bytesToInt(byte[] bytes) {
|
|
|
+ return ByteBuffer.wrap(bytes).getInt();
|
|
|
+ }
|
|
|
+ public static int bytesToInt(byte[] bytes, int fromIdx, ByteOrder byteOrder) {
|
|
|
+
|
|
|
+ if (byteOrder == ByteOrder.BIG_ENDIAN) {
|
|
|
+ return (
|
|
|
+ ((bytes[fromIdx+0] & 0xFF) << 24) |
|
|
|
+ ((bytes[fromIdx+1] & 0xFF) << 16) |
|
|
|
+ ((bytes[fromIdx+2] & 0xFF) << 8 ) |
|
|
|
+ ((bytes[fromIdx+3] & 0xFF) << 0 )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return (
|
|
|
+ ((bytes[fromIdx+3] & 0xFF) << 24) |
|
|
|
+ ((bytes[fromIdx+2] & 0xFF) << 16) |
|
|
|
+ ((bytes[fromIdx+1] & 0xFF) << 8 ) |
|
|
|
+ ((bytes[fromIdx+0] & 0xFF) << 0 )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public static byte[] intToBytes(int value) {
|
|
|
+ // BIG_ENDIAN
|
|
|
+ return ByteBuffer.allocate(4).putInt(value).array();
|
|
|
+ }
|
|
|
}
|