Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.security.GeneralSecurityException;

public class Main {
    /**
     * Returns the concatenation of the input arrays in a single array. For example,
     * {@code concat(new byte[] {a, b}, new byte[] {}, new byte[] {c}} returns the array
     * {@code {a, b, c}}.
     *
     * @return a single array containing all the values from the source arrays, in order
     */
    public static byte[] concat(byte[]... chunks) throws GeneralSecurityException {
        int length = 0;
        for (byte[] chunk : chunks) {
            if (length > Integer.MAX_VALUE - chunk.length) {
                throw new GeneralSecurityException("exceeded size limit");
            }
            length += chunk.length;
        }
        byte[] res = new byte[length];
        int pos = 0;
        for (byte[] chunk : chunks) {
            System.arraycopy(chunk, 0, res, pos, chunk.length);
            pos += chunk.length;
        }
        return res;
    }
}