001package com.nimbusds.jose.util;
002
003
004import java.util.Arrays;
005
006
007/**
008 * Array utilities.
009 */
010public class ArrayUtils {
011        
012        
013        /**
014         * Concatenates the specified arrays.
015         *
016         * @param first The first array. Must not be {@code null}.
017         * @param rest  The remaining arrays.
018         * @param <T>   The array type.
019         *
020         * @return The resulting array.
021         */
022        public static <T> T[] concat(final T[] first, final T[]... rest) {
023                int totalLength = first.length;
024                for (T[] array : rest) {
025                        totalLength += array.length;
026                }
027                T[] result = Arrays.copyOf(first, totalLength);
028                int offset = first.length;
029                for (T[] array : rest) {
030                        System.arraycopy(array, 0, result, offset, array.length);
031                        offset += array.length;
032                }
033                return result;
034        }
035        
036        
037        /**
038         * Prevents public instantiation.
039         */
040        private ArrayUtils() {
041        }
042}