Here you can find the source of truncate(byte[] array, int newLength)
Parameter | Description |
---|---|
array | the array to be truncated. |
newLength | the new length in bytes. |
public static byte[] truncate(byte[] array, int newLength)
//package com.java2s; public class Main { /**/*from ww w. ja v a2 s . c o m*/ * Truncates the given array to the request length. * * @param array * the array to be truncated. * @param newLength * the new length in bytes. * @return the truncated array. */ public static byte[] truncate(byte[] array, int newLength) { if (array.length < newLength) { return array; } else { byte[] truncated = new byte[newLength]; System.arraycopy(array, 0, truncated, 0, newLength); return truncated; } } }