package Sense4; /** * @author Lanlan * @date 2018/11/25 */ public abstract class LockUtils { private static EliteLockIO intance; public static boolean isJVMSystem32() { String arch_model = System.getProperty("sun.arch.data.model"); return "32".equals(arch_model); } // big-endian public static byte[] intToByteArray1(int i) { byte[] result = new byte[4]; result[0] = (byte)((i >> 24) & 0xFF); result[1] = (byte)((i >> 16) & 0xFF); result[2] = (byte)((i >> 8) & 0xFF); result[3] = (byte)(i & 0xFF); return result; } // big-endian public static int byteArray2Int(byte[] bytes) { int res = 0; res += (bytes[0] & 0xff) << 24; res += (bytes[1] & 0xff) << 16; res += (bytes[2] & 0xff)<< 8; res += bytes[3] & 0xff; return res; } public static String toHexString(byte[] b) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < b.length; i++) { String hex = Integer.toHexString(b[i] & 0xFF); if (hex.length() == 1) { hex = "0" + hex; } sb.append(hex); } return sb.toString(); } public static void main(String[] args) { System.out.println("System is 32-bit: " + isJVMSystem32()); } public static EliteLockIO getEliteLockIOInstance() { if (intance == null) { if (isJVMSystem32()) { intance = new EliteLockIO32(); } else { intance = new EliteLockIO64(); } } return intance; } }