Here you can find the source of getArrays(byte[] inputArray, int arraySize, boolean zeroPad)
Parameter | Description |
---|---|
inputArray | An array of bytes |
arraySize | The size of each array object returned in the Enumeration |
zeroPad | Add a padding of zeros if the last array returned is shorter than arraySize |
public static byte[][] getArrays(byte[] inputArray, int arraySize, boolean zeroPad)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { /**//from ww w . j av a 2s .co m * Convert a large byte array into multiple smaller byte arrays, with the * output size determined by the caller * * @param inputArray * An array of bytes * @param arraySize * The size of each array object returned in the Enumeration * @param zeroPad * Add a padding of zeros if the last array returned is shorter * than arraySize * @return Enumeration An Enumeration of byte arrays of the size specified * by the caller */ public static byte[][] getArrays(byte[] inputArray, int arraySize, boolean zeroPad) { byte[][] tdba = new byte[(int) Math.ceil(inputArray.length / (double) arraySize)][arraySize]; int start = 0; for (int i = 0; i < tdba.length; i++) { if (start + arraySize > inputArray.length) { byte[] lastArray; if (zeroPad) { lastArray = new byte[arraySize]; Arrays.fill(lastArray, (byte) 0x00); } else { lastArray = new byte[inputArray.length - start]; } System.arraycopy(inputArray, start, lastArray, 0, inputArray.length - start); tdba[i] = lastArray; } else { System.arraycopy(inputArray, start, tdba[i], 0, arraySize); } start += arraySize; } return tdba; } }