|
@@ -1,11 +1,26 @@
|
|
|
package com.its.common.utils;
|
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+
|
|
|
public class ByteUtils {
|
|
|
|
|
|
private ByteUtils() {}
|
|
|
|
|
|
private static final int[] BYTE_MASKED_ARRAY = { 1, 2, 4, 8, 16, 32, 64, 128 };
|
|
|
|
|
|
+ public static void copyStringToByteArray(byte[] dest, String data) {
|
|
|
+ //byte[] byteData = data.getBytes();
|
|
|
+ byte[] byteData = data.getBytes(StandardCharsets.UTF_8);
|
|
|
+ int size = dest.length;
|
|
|
+ int ii;
|
|
|
+ for (ii = 0; ii < byteData.length && ii < size; ii++) {
|
|
|
+ dest[ii] = byteData[ii];
|
|
|
+ }
|
|
|
+ for (int jj = ii; jj < size; jj++) {
|
|
|
+ dest[jj] = 0x00;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static short getShort(byte[] data, int start) {
|
|
|
return (short)(data[start ] << 8 |
|
|
|
data[start+1] & 0xFF);
|