Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static byte[] truncByteArray(byte[] array, int size) { if (size <= array.length) { byte[] output = new byte[size]; System.arraycopy(array, 0, output, 0, size); return output; } return array; } }