Here you can find the source of combine(byte[]... bytes)
Parameter | Description |
---|---|
bytes | Array to be merged together |
public static byte[] combine(byte[]... bytes)
//package com.java2s; /*//from w ww .j av a 2 s. c o m * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ public class Main { /** * Merge multiple Byte Arrays into one * * @param bytes Array to be merged together * @return Merged Arrays */ public static byte[] combine(byte[]... bytes) { if (bytes == null) { return null; } else if (bytes.length == 1) { return bytes[0]; } int combinedLength = 0; for (byte[] _bytes : bytes) { if (_bytes != null) { combinedLength += _bytes.length; } } byte[] combined = new byte[combinedLength]; int shift = 0; for (byte[] aByte : bytes) { if (aByte != null) { System.arraycopy(aByte, 0, combined, shift, aByte.length); shift += aByte.length; } } return combined; } }