Here you can find the source of toArray(long length)
public static byte[] toArray(long length)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; public class Main { public static byte[] toArray(long length) { long value = length; byte[] b = new byte[8]; for (int i = 7; i >= 0 && value > 0; i--) { b[i] = (byte) (value & 0xFF); value >>= 8;/* w w w.j a va2s. c o m*/ } return b; } public static byte[] toArray(int value) { ByteBuffer b = ByteBuffer.allocate(4); return b.putInt(value).array(); } }