Here you can find the source of toBytes(int value)
public static byte[] toBytes(int value)
//package com.java2s; import java.nio.ByteBuffer; public class Main { public static byte[] toBytes(int value) { ByteBuffer buffer = ByteBuffer.allocate(4); buffer.putInt(value).flip();//w w w. j a va 2 s .c om return readBytes(buffer, 4); } public static byte[] readBytes(ByteBuffer buffer, int length) { if (buffer == null || length <= 0) { return null; } byte[] bytes = new byte[length]; buffer.get(bytes); return bytes; } }