### Question:
ByteUtil { public static byte[] nextKey(byte[] key) { byte[] nextStartRow = new byte[key.length]; System.arraycopy(key, 0, nextStartRow, 0, key.length); if (!nextKey(nextStartRow, nextStartRow.length)) { return null; } return nextStartRow; }  static byte[] toBytes(byte[][] byteArrays); static byte[][] toByteArrays(byte[] b, int length); static byte[][] toByteArrays(byte[] b, int offset, int length); static byte[] serializeVIntArray(int[] intArray); static byte[] serializeVIntArray(int[] intArray, int encodedLength); static void serializeVIntArray(DataOutput output, int[] intArray); static void serializeVIntArray(DataOutput output, int[] intArray, int encodedLength); static long[] readFixedLengthLongArray(DataInput input, int length); static void writeFixedLengthLongArray(DataOutput output, long[] longArray); static int[] deserializeVIntArray(byte[] b); static int[] deserializeVIntArray(DataInput in); static int[] deserializeVIntArray(DataInput in, int length); static int[] deserializeVIntArray(byte[] b, int length); static byte[] concat(byte[] first, byte[]... rest); static T[] concat(T[] first, T[]... rest); static byte[] concat(SortOrder sortOrder, ImmutableBytesWritable... writables); static int vintFromBytes(byte[] buffer, int offset); static int vintFromBytes(ImmutableBytesWritable ptr); static long vlongFromBytes(ImmutableBytesWritable ptr); static int vintToBytes(byte[] result, int offset, final long vint); static byte[] nextKey(byte[] key); static boolean nextKey(byte[] key, int length); static boolean nextKey(byte[] key, int offset, int length); static byte[] previousKey(byte[] key); static boolean previousKey(byte[] key, int length); static boolean previousKey(byte[] key, int offset, int length); static byte[] fillKey(byte[] key, int length); static void nullPad(ImmutableBytesWritable ptr, int length); static int getSize(CharSequence sequence); static boolean isInclusive(CompareOp op); static boolean compare(CompareOp op, int compareResult); static byte[] copyKeyBytesIfNecessary(ImmutableBytesWritable ptr); static KeyRange getKeyRange(byte[] key, CompareOp op, PDataType type); static boolean contains(Collection<byte[]> keys, byte[] key); static boolean contains(List<ImmutableBytesPtr> keys, ImmutableBytesPtr key); static boolean match(Set<byte[]> keys, Set<byte[]> keys2); static byte[] calculateTheClosestNextRowKeyForPrefix(byte[] rowKeyPrefix); static byte[][] splitArrayBySeparator(byte[] src, byte separator); static final byte[] EMPTY_BYTE_ARRAY; static final ImmutableBytesPtr EMPTY_BYTE_ARRAY_PTR; static final ImmutableBytesWritable EMPTY_IMMUTABLE_BYTE_ARRAY; static final Comparator<ImmutableBytesPtr> BYTES_PTR_COMPARATOR; }### Answer:
@Test public void testNextKey() { byte[] key = new byte[] {1}; assertEquals((byte)2, ByteUtil.nextKey(key)[0]); key = new byte[] {1, (byte)255}; byte[] nextKey = ByteUtil.nextKey(key); byte[] expectedKey = new byte[] {2,(byte)0}; assertArrayEquals(expectedKey, nextKey); key = ByteUtil.concat(Bytes.toBytes("00D300000000XHP"), PInteger.INSTANCE.toBytes(Integer.MAX_VALUE)); nextKey = ByteUtil.nextKey(key); expectedKey = ByteUtil.concat(Bytes.toBytes("00D300000000XHQ"), PInteger.INSTANCE.toBytes(Integer.MIN_VALUE)); assertArrayEquals(expectedKey, nextKey); key = new byte[] {(byte)255}; assertNull(ByteUtil.nextKey(key)); }