Here you can find the source of longToBytes(long x, byte[] dest, int offset)
public static void longToBytes(long x, byte[] dest, int offset)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; import java.util.concurrent.locks.ReentrantLock; public class Main { private static ByteBuffer longbuffer = ByteBuffer.allocate(Long.BYTES); private static ReentrantLock bufferLock = new ReentrantLock(); public static void longToBytes(long x, byte[] dest, int offset) { bufferLock.lock();/*from w w w. j a va 2 s . co m*/ try { longbuffer.clear(); longbuffer.putLong(0, x); System.arraycopy(longbuffer.array(), 0, dest, offset, Long.BYTES); } finally { bufferLock.unlock(); } } }