Here you can find the source of copyBytes(byte[] arr, int length)
public static byte[] copyBytes(byte[] arr, int length)
//package com.java2s; public class Main { public static byte[] copyBytes(byte[] arr, int length) { byte[] newArr = null; if (arr == null || arr.length == length) { newArr = arr;/* ww w. j a v a 2 s . c o m*/ } else { newArr = new byte[length]; for (int i = 0; i < length; i++) { newArr[i] = (byte) arr[i]; } } return newArr; } }