From e0cebbba864a3200d9579bf8401efd96fcd50c6e Mon Sep 17 00:00:00 2001 From: Roman Mandeleil Date: Wed, 25 Feb 2015 19:13:24 +0200 Subject: [PATCH] Introduce merge arrays function --- .../main/java/org/ethereum/util/ByteUtil.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java b/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java index 80ca6ebc..163afc15 100644 --- a/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/ByteUtil.java @@ -349,4 +349,29 @@ public class ByteUtil { byte dataByte = data[posByte]; return Math.min(1, (dataByte & (1 << (posBit)))); } + + + /** + * @param arrays - arrays to merge + * @return - merged array + */ + public static byte[] merge(byte[]... arrays) + { + int arrCount = 0; + int count = 0; + for (byte[] array: arrays) + { + arrCount++; + count += array.length; + } + + // Create new array and copy all array contents + byte[] mergedArray = new byte[count]; + int start = 0; + for (byte[] array: arrays) { + System.arraycopy(array, 0, mergedArray, start, array.length); + start += array.length; + } + return mergedArray; + } } \ No newline at end of file