Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static byte[] concatAll(byte[] first, byte[]... rest) {
        int i, lenOfReadBytes;
        int totalLength = lenOfReadBytes = i = first != null ? first.length : 0;
        for (byte[] array : rest) {
            if (array != null)
                totalLength += array.length;
        }
        byte[] result = new byte[totalLength];

        if (first != null) {
            System.arraycopy(first, 0, result, 0, first.length);
        }

        int b = 0;
        for (; i < totalLength; i++) {
            if (rest == null)
                b++;
            if (i >= rest[b].length + lenOfReadBytes) {
                lenOfReadBytes += rest[b++].length;
            }
            result[i] = rest[b][i - lenOfReadBytes];
        }
        return result;
    }
}