Here you can find the source of splitByteArray(byte[] array, int each)
Parameter | Description |
---|---|
array | the array to split |
each | the size of each piece |
public static byte[][] splitByteArray(byte[] array, int each)
//package com.java2s; import java.util.Arrays; public class Main { /**//from w w w.j a v a 2s . c om * Split the byte array into pieces of the given size, the last piece may not have the same size of the others. * * @param array the array to split * @param each the size of each piece * @return the 2D array with the pieces */ public static byte[][] splitByteArray(byte[] array, int each) { int slice = (int) Math.floor(array.length / each); byte[][] slices = new byte[slice + 1][]; int read = 0; for (int j1 = 0; j1 < slices.length; j1++) { int to = read + each; if (to > array.length) { to = array.length; } slices[j1] = Arrays.copyOfRange(array, read, to); read += each; } return slices; } }