Here you can find the source of ToByteArray(long[] data)
private static byte[] ToByteArray(long[] data)
//package com.java2s; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.List; public class Main { private static char SPECIAL_CHAR = '\0'; private static byte[] ToByteArray(long[] data) { List<Byte> result = new ArrayList<Byte>(); for (int i = 0; i < data.length; i++) { byte[] bs = long2bytes(data[i]); for (int j = 0; j < 8; j++) { result.add(bs[j]);//from www . j av a 2 s .c o m } } while (result.get(result.size() - 1) == SPECIAL_CHAR) { result.remove(result.size() - 1); } byte[] ret = new byte[result.size()]; for (int i = 0; i < ret.length; i++) { ret[i] = result.get(i); } return ret; } public static byte[] long2bytes(long num) { ByteBuffer buffer = ByteBuffer.allocate(8).order( ByteOrder.LITTLE_ENDIAN); buffer.putLong(num); return buffer.array(); } }