static Bytes upperRange(final Bytes key, final byte[] maxSuffix) {
        final byte[] bytes = key.get();
        final ByteBuffer rangeEnd = ByteBuffer.allocate(bytes.length + maxSuffix.length);
        final int firstTimestampByte = maxSuffix[0] & 0xFF;

        // if firstTimestampByte is 0, we'll put all key bytes into range result because `(bytes[i] & 0xFF) >= firstTimestampByte`
        // will always be true (this is a byte to unsigned int conversion comparison)
        if (firstTimestampByte == 0) {
            return Bytes.wrap(
                rangeEnd
                    .put(bytes)
                    .put(maxSuffix)
                    .array()
            );
        } else {
            int i = 0;
            while (i < bytes.length && (
                i < MIN_KEY_LENGTH // assumes keys are at least one byte long
                || (bytes[i] & 0xFF) >= firstTimestampByte
                )) {
                rangeEnd.put(bytes[i++]);
            }

            rangeEnd.put(maxSuffix);
            rangeEnd.flip();

            final byte[] res = new byte[rangeEnd.remaining()];
            ByteBuffer.wrap(res).put(rangeEnd);
            return Bytes.wrap(res);
        }
    }
Returns the upper byte range for a key with a given fixed size maximum suffix

Assumes the minimum key length is one byte
streams/src/main/java/org/apache/kafka/streams/state/internals/OrderedBytes.java