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;
  }
}

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 ; } }
truncates the given array to the request length .
