### Question:
ByteArrays { public static byte[] cut(ByteArray byteArray, long offset, int length) { long o = 0L; int i = 0; while (true) { int localLength = byteArray.bytes[i].length; if ((o + localLength) <= offset) { o += localLength; i++; } else { byte[] copy = new byte[length]; int copyOffset = 0; while (length > 0) { int localOffset = (int) (offset - o); int copyLength = byteArray.bytes[i].length - localOffset; if (copyLength > length) { copyLength = length; } if ((copyOffset == 0) && (localOffset == 0) && (length == byteArray.bytes[i].length)) { return byteArray.bytes[i]; } System.arraycopy(byteArray.bytes[i], localOffset, copy, copyOffset, copyLength); length -= copyLength; copyOffset += copyLength; o += copyLength; offset = o; i++; } return copy; } } } private  ByteArrays(); static ByteArray empty(); static ByteArray cat(ByteArray... byteArrays); static long totalLength(ByteArray byteArray); static boolean isEmpty(ByteArray byteArray); static byte[] flattened(ByteArray byteArray); static byte[] cut(ByteArray byteArray, long offset, int length); static String representation(ByteArray byteArray); static ByteArray fromRepresentation(String representationAsBase64); static ByteArray utf8(String s); static String utf8(ByteArray byteArray);  }### Answer:
@Test public void testCut() throws Exception { ByteArray b = new ByteArray(new byte[][] { testBytes(0, 3), testBytes(3, 4), testBytes(7, 5) }); Assertions.assertThat(ByteArrays.cut(b, 0, 3)).isEqualTo(testBytes(0, 3)); Assertions.assertThat(ByteArrays.cut(b, 0, 3) == b.bytes[0]).isTrue(); Assertions.assertThat(ByteArrays.cut(b, 3, 4) == b.bytes[1]).isTrue(); Assertions.assertThat(ByteArrays.cut(b, 1, 2)).isEqualTo(testBytes(1, 2)); Assertions.assertThat(ByteArrays.cut(b, 1, 3)).isEqualTo(testBytes(1, 3)); Assertions.assertThat(ByteArrays.cut(b, 0, 11)).isEqualTo(testBytes(0, 11)); Assertions.assertThat(ByteArrays.cut(b, 1, 11)).isEqualTo(testBytes(1, 11)); Assertions.assertThat(ByteArrays.cut(b, 3, 8)).isEqualTo(testBytes(3, 8)); Assertions.assertThat(ByteArrays.cut(b, 3, 9)).isEqualTo(testBytes(3, 9)); Assertions.assertThat(ByteArrays.cut(b, 0, 0)).isEqualTo(testBytes(0, 0)); Assertions.assertThat(ByteArrays.cut(b, 1, 0)).isEqualTo(testBytes(1, 0)); Assertions.assertThat(ByteArrays.cut(b, 3, 0)).isEqualTo(testBytes(3, 0)); }