|
12 | 12 | import java.nio.file.Files; |
13 | 13 | import java.nio.file.Path; |
14 | 14 | import java.security.AlgorithmParameters; |
15 | | -import java.util.ArrayList; |
16 | | -import java.util.Base64; |
17 | | -import java.util.Collections; |
18 | | -import java.util.List; |
| 15 | +import java.util.*; |
| 16 | +import java.util.regex.Matcher; |
19 | 17 | import java.util.regex.Pattern; |
20 | 18 | import java.util.stream.Stream; |
21 | 19 |
|
22 | 20 | @NullMarked |
23 | 21 | public class TestChunks { |
24 | 22 |
|
25 | | - public static final Pattern shardFolderPattern = Pattern.compile("shard-\\d+"); |
26 | | - public static final Pattern decompressedChunkPattern = Pattern.compile("chunk-\\d+\\.bin"); |
| 23 | + public static final Pattern shardFolderPattern = Pattern.compile("shard-(\\d+)"); |
| 24 | + public static final Pattern decompressedChunkPattern = Pattern.compile("chunk-(\\d+)\\.bin"); |
| 25 | + |
| 26 | + private static final Comparator<Path> shardFolderComparator = Comparator.comparingInt(path -> { |
| 27 | + Matcher matcher = shardFolderPattern.matcher(path.getFileName().toString()); |
| 28 | + if (!matcher.matches()) { |
| 29 | + throw new IllegalArgumentException("Invalid shard folder path: " + path); |
| 30 | + } |
| 31 | + return Integer.parseInt(matcher.group(1)); |
| 32 | + }); |
| 33 | + |
| 34 | + private static final Comparator<Path> decompressedChunkComparator = Comparator.comparingInt(path -> { |
| 35 | + Matcher matcher = decompressedChunkPattern.matcher(path.getFileName().toString()); |
| 36 | + if (!matcher.matches()) { |
| 37 | + throw new IllegalArgumentException("Invalid decompressed chunk path: " + path); |
| 38 | + } |
| 39 | + return Integer.parseInt(matcher.group(1)); |
| 40 | + }); |
27 | 41 |
|
28 | 42 | public static List<List<Chunk>> get() { |
29 | 43 | final EncryptedTestData encryptedTestData = getEncryptedTestData(); |
@@ -71,10 +85,10 @@ private static EncryptedTestData getEncryptedTestData() { |
71 | 85 |
|
72 | 86 | List<List<Chunk>> shards = new ArrayList<>(); |
73 | 87 | try (Stream<Path> shardDirStream = Files.walk(chunksDirectory, 1)) { |
74 | | - for (Path shardDir : shardDirStream.filter(TestChunks::isShardFolder).sorted().toList()) { |
| 88 | + for (Path shardDir : shardDirStream.filter(TestChunks::isShardFolder).sorted(shardFolderComparator).toList()) { |
75 | 89 | List<Chunk> chunks = new ArrayList<>(); |
76 | 90 | try (Stream<Path> chunkStream = Files.walk(shardDir, 1)) { |
77 | | - for (Path path : chunkStream.filter(TestChunks::isDecompressedChunk).sorted().toList()) { |
| 91 | + for (Path path : chunkStream.filter(TestChunks::isDecompressedChunk).sorted(decompressedChunkComparator).toList()) { |
78 | 92 | byte[] decompressed = Files.readAllBytes(path); |
79 | 93 | byte[] zlibCompressed = Files.readAllBytes(path.resolveSibling(path.getFileName().toString() + ".zlib")); |
80 | 94 | byte[] zstdCompressed = Files.readAllBytes(path.resolveSibling(path.getFileName().toString() + ".zstd")); |
|
0 commit comments