Here you can find the source of bytesToLong(byte[] bytes)
public static long bytesToLong(byte[] bytes)
//package com.java2s; import java.nio.ByteBuffer; public class Main { private static ByteBuffer buffer = ByteBuffer.allocate(8); public static long bytesToLong(byte[] bytes) { if (bytes == null) { return 0l; }/*from w ww .j a v a 2 s. c o m*/ if (bytes.length < 8) { byte[] mask = new byte[(8 - bytes.length)]; bytes = append(mask, bytes); } buffer.clear(); buffer.put(bytes, 0, 8); buffer.flip();//need flip return buffer.getLong(); } public static byte[] append(byte[] data, byte[] adata) { if (data == null) { data = new byte[0]; } int len = data.length; if (adata == null) { return data; } int alen = adata.length; byte[] result = new byte[(len + alen)]; for (int i = 0, j = 0; i < len + alen; i++) { if (i < len) { result[i] = data[i]; continue; } result[i] = adata[j]; j++; } return result; } }