DataUtils { public final static long byteArrayToUnsignedLong(final byte [] src) { long value = 0; for(int i = 0; i < src.length; i++) { value = value << 8; int b = (src[i]) & 0xFF; value |= b; } return value; }  static int compare(T left, T right); static int compare(byte [] left, byte [] right); static int compare(ArrayList<byte []> left, ArrayList<byte []> right); static String printBytes(byte [] bytes); static String printHexBytes(byte [] bytes); static byte [] base64Decode(byte [] input); static byte [] base64Encode(byte [] input); static String base64Encode(byte [] input, Integer lineLength); @Deprecated static byte [] lineWrapBase64(byte [] input, int lineLength); static String lineWrap(String inputString, int lineLength); static boolean arrayEquals(byte[] left, byte[] right); static boolean arrayEquals(byte[] left, byte[] right, int length); static boolean isBinaryPrefix(byte [] prefix, byte [] data); static void deleteDirectory(File directory); static byte[] getBytesFromFile(File file); static byte [] getBytesFromStream(InputStream input); static String getUTF8StringFromBytes(byte [] stringBytes); static byte [] getBytesFromUTF8String(String stringData); static int bytencmp(byte[] arr1, int offset1, byte[] arr2, int offset2, int count); static int bytencmp(byte [] arr1, byte [] arr2, int count); static int byteindex(byte [] array, int startingOffset, byte byteToFind); static int byteindex(byte [] array, byte byteToFind); static int byterindex(byte [] array, int startingOffset, byte byteToFind); static int byterindex(byte [] array, byte byteToFind); static int occurcount(byte [] array, int startingOffset, int length, byte byteToFind); static int occurcount(byte [] array, int length, byte byteToFind); static int occurcount(byte [] array, byte byteToFind); static byte [][] binarySplit(byte [] array, int startingOffset, byte splitValue); static byte [][] binarySplit(byte [] array, byte splitValue); static byte [] subarray(byte [] array, int offset, int len); final static long byteArrayToUnsignedLong(final byte [] src); final static long byteArrayToUnsignedLong(final byte [] src, int start); final static byte [] unsignedLongToByteArray(final long value); final static byte [] unsignedLongToByteArray(final long value, final byte firstByte); static final int BITS_PER_BYTE; static final String EMPTY; static final String LINE_SEPARATOR; static Charset UTF8_CHARSET; static final int LINELEN; }
@Test public void testByteArrayToUnsignedLong() throws Exception { for(long v : testset) { byte [] b = longToByteArray(v); long truth = new BigInteger(1, b).longValue(); long test = DataUtils.byteArrayToUnsignedLong(b); Assert.assertEquals(truth, test); } }