ArrayUtils { public static Byte[][] toByteArray(final byte[][] array) { if (array == null) { return null; } final Byte[][] byteArray = new Byte[array.length][]; for (int i = 0; i < array.length; i++) { byteArray[i] = new Byte[array[i].length]; for (int j = 0; j < array[i].length; j++) { byteArray[i][j] = array[i][j]; } } return byteArray; }  static T getElementAtIndex(T[] array, int index, T defaultValue); static T getFirst(final T... array); static String toString(final Object... array); static String toString(final String... array); static Object[] insert(Object[] originalArray, int pos, Object element); static Object[] remove(Object[] originalArray, int pos); static String objectRefString(Object obj); static void objectRefString(Object obj, StringBuilder sb); static String objectString(Object obj); static void objectString(Object obj, StringBuilder sb); static String objectStringNonRecursive(@Unretained Object obj); static boolean areByteArrayArrayEquals(byte[][] v1, byte[][] v2); static void objectStringNonRecursive(@Unretained Object obj, StringBuilder sb); static boolean objectEquals(Object o1, Object o2); static Integer[] toIntegerArray(final int[] array); static Byte[][] toByteArray(final byte[][] array); static byte[][] toBytes(final Byte[][] byteArray); static List<T> asList(T... array);  }
@Test public void toByteArray_returnsBytes() { int count = 0; byte[][] array = new byte[10][5]; for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[i].length; j++) { array[i][j] = (byte) ++count; } } assertThat(count).isEqualTo(50); count = 0; Byte[][] byteArray = toByteArray(array); for (int i = 0; i < byteArray.length; i++) { for (int j = 0; j < byteArray[i].length; j++) { assertThat(byteArray[i][j].byteValue()).isEqualTo((byte) ++count); } } assertThat(count).isEqualTo(50); }
@Test public void toByteArray_empty_returnsEmptyBytes() { byte[][] array = new byte[0][0]; assertThat(toByteArray(array)).isEqualTo(new Byte[0][0]); }
@Test public void toByteArray_null_returnsNull() { byte[][] array = null; assertThat(toByteArray(array)).isNull(); }