|
31 | 31 | import java.util.ArrayList; |
32 | 32 | import java.util.Base64; |
33 | 33 | import java.util.List; |
| 34 | +import java.util.UUID; |
34 | 35 | import java.util.concurrent.ThreadLocalRandom; |
35 | 36 | import java.util.function.BiFunction; |
36 | 37 | import java.util.stream.Collectors; |
@@ -559,65 +560,20 @@ private static void validateUuid(String uuid) { |
559 | 560 |
|
560 | 561 | private static long[] parseUuid(String uuid) { |
561 | 562 | String originalUuid = uuid; |
562 | | - |
563 | | - // Handle optional braces |
564 | 563 | if (uuid.startsWith("{")) { |
565 | 564 | if (!uuid.endsWith("}")) { |
566 | 565 | throw new IllegalArgumentException("Invalid UUID string: " + originalUuid); |
567 | 566 | } |
568 | 567 | uuid = uuid.substring(1, uuid.length() - 1); |
569 | | - } |
570 | | - |
571 | | - // Minimum 36 characters required (standard UUID format: 8-4-4-4-12) |
572 | | - if (uuid.length() < 36) { |
573 | | - throw new IllegalArgumentException("Invalid UUID string: " + originalUuid); |
574 | | - } |
575 | | - |
576 | | - // Check for leading hyphen |
577 | | - if (uuid.startsWith("-")) { |
| 568 | + } else if (uuid.endsWith("}")) { |
578 | 569 | throw new IllegalArgumentException("Invalid UUID string: " + originalUuid); |
579 | 570 | } |
580 | | - |
581 | | - // Parse 32 hex digits (ignoring hyphens in between) |
582 | | - long high = 0; |
583 | | - long low = 0; |
584 | | - int hexCount = 0; |
585 | | - |
586 | | - for (int i = 0; i < uuid.length(); i++) { |
587 | | - char c = uuid.charAt(i); |
588 | | - if (c == '-') { |
589 | | - continue; // Skip hyphens |
590 | | - } |
591 | | - int digit = hexDigit(c); |
592 | | - if (digit < 0) { |
593 | | - throw new IllegalArgumentException("Invalid UUID string: " + originalUuid); |
594 | | - } |
595 | | - if (hexCount < 16) { |
596 | | - high = (high << 4) | digit; |
597 | | - } else { |
598 | | - low = (low << 4) | digit; |
599 | | - } |
600 | | - hexCount++; |
601 | | - } |
602 | | - |
603 | | - if (hexCount != 32) { |
604 | | - throw new IllegalArgumentException("Invalid UUID string: " + originalUuid); |
605 | | - } |
606 | | - |
607 | | - // After parsing, verify there are no trailing characters |
608 | | - // (uuid must be exactly consumed) |
609 | | - if (uuid.length() > 36) { |
610 | | - throw new IllegalArgumentException("Invalid UUID string: " + originalUuid); |
| 571 | + try { |
| 572 | + UUID parsed = UUID.fromString(uuid); |
| 573 | + return new long[] {parsed.getMostSignificantBits(), parsed.getLeastSignificantBits()}; |
| 574 | + } catch (IllegalArgumentException e) { |
| 575 | + throw new IllegalArgumentException("Invalid UUID string: " + originalUuid, e); |
611 | 576 | } |
612 | | - |
613 | | - return new long[] {high, low}; |
614 | | - } |
615 | | - |
616 | | - private static int hexDigit(char c) { |
617 | | - if (c >= '0' && c <= '9') return c - '0'; |
618 | | - if (c >= 'a' && c <= 'f') return 10 + (c - 'a'); |
619 | | - if (c >= 'A' && c <= 'F') return 10 + (c - 'A'); |
620 | | - return -1; |
621 | 577 | } |
622 | 578 |
|
623 | 579 | private TargetRange encodeKeyInternal( |
|
0 commit comments