ArrayUtils { public static byte[][] toBytes(final Byte[][] byteArray) { if (byteArray == null) { return null; } final byte[][] array = new byte[byteArray.length][]; for (int i = 0; i < byteArray.length; i++) { array[i] = new byte[byteArray[i].length]; for (int j = 0; j < byteArray[i].length; j++) { array[i][j] = byteArray[i][j]; } } return array; }  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 toBytes_returnsPrimitiveBytes() { int count = 100; Byte[][] byteArray = new Byte[5][10]; for (int i = 0; i < byteArray.length; i++) { for (int j = 0; j < byteArray[i].length; j++) { byteArray[i][j] = (byte) --count; } } assertThat(count).isEqualTo(50); count = 100; byte[][] array = toBytes(byteArray); for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[i].length; j++) { assertThat(array[i][j]).isEqualTo((byte) --count); } } assertThat(count).isEqualTo(50); }
@Test public void toBytes_empty_returnsEmpty() { Byte[][] byteArray = new Byte[0][0]; assertThat(toBytes(byteArray)).isEqualTo(new byte[0][0]); }
@Test public void toBytes_null_returnsNull() { Byte[][] byteArray = null; assertThat(toBytes(byteArray)).isNull(); }