Here you can find the source of copyBytes(byte[] dst, int dstPos, int value)
public static void copyBytes(byte[] dst, int dstPos, int value)
//package com.java2s; public class Main { public static void copyBytes(byte[] dst, int dstPos, int value) { byte[] valueBytes = toByteArray(value); System.arraycopy(valueBytes, 0, dst, dstPos, valueBytes.length); }/*w ww. j a va2 s .c o m*/ public static void copyBytes(byte[] dst, int dstPos, short value) { byte[] valueBytes = toByteArray(value); System.arraycopy(valueBytes, 0, dst, dstPos, valueBytes.length); } public static void copyBytes(byte[] dst, int dstPos, byte value) { dst[dstPos] = value; } public static void copyBytes(byte[] dst, int dstPos, String value) { byte[] valueBytes = value.getBytes(); System.arraycopy(valueBytes, 0, dst, dstPos, valueBytes.length); } public static byte[] toByteArray(long value) { byte[] b = new byte[8]; for (int i = 0; i < 8; i++) { int offset = (8 - 1 - i) * 8; b[i] = (byte) (value >>> offset & 0xFF); } return b; } public static byte[] toByteArray(int value) { byte[] b = new byte[4]; for (int i = 0; i < 4; i++) { int offset = (4 - 1 - i) * 8; b[i] = (byte) (value >>> offset & 0xFF); } return b; } public static byte[] toByteArray(short value) { byte[] b = new byte[2]; for (int i = 0; i < 2; i++) { int offset = (2 - 1 - i) * 8; b[i] = (byte) (value >>> offset & 0xFF); } return b; } }