code: public static byte[] copyWithLength(byte[] orig, int length) {
      // No need to initialize with zero bytes, because the bytes are already initialized with that
      byte[] result = new byte[length];
      int howMuchToCopy = length < orig.length ? length : orig.length;
      System.arraycopy(orig, 0, result, 0, howMuchToCopy);
      return result;
    }
docs: Copies the original byte array content to a new byte array. The resulting byte array is always
  "length" size. If length is smaller than the original byte array, the resulting byte array is
  truncated. If length is bigger than the original byte array, the resulting byte array is filled
  with zero bytes.
  
  @param orig   the original byte array
  @param length how big the resulting byte array will be
  @return the copied byte array