concatenate list of byte array to single byte array - Android File Input Output

Android examples for File Input Output:Byte Array Convert

Description

concatenate list of byte array to single byte array

Demo Code

/**/*from  w  ww .jav  a 2  s .  c om*/
 * Source obtained from crypto-gwt. Apache 2 License.
 * https://code.google.com/p/crypto-gwt/source/browse/crypto-gwt/src/main/java/com/googlecode/
 * cryptogwt/util/ByteArrayUtils.java
 */
//package com.book2s;

public class Main {
    public static byte[] concatenate(byte[]... bytes) {
        int length = 0;
        for (byte[] array : bytes)
            length += array.length;
        byte[] result = new byte[length];
        int offset = 0;
        for (byte[] array : bytes) {
            System.arraycopy(array, 0, result, offset, array.length);
            offset += array.length;
        }
        return result;
    }
}

Related Tutorials