|
33 | 33 | import net.jpountz.lz4.LZ4Compressor; |
34 | 34 | import net.jpountz.lz4.LZ4Factory; |
35 | 35 | import net.jpountz.lz4.LZ4FastDecompressor; |
| 36 | +import net.jpountz.xxhash.XXHashFactory; |
36 | 37 | import org.apache.logging.log4j.Logger; |
37 | 38 | import org.enginehub.linbus.tree.LinCompoundTag; |
38 | 39 |
|
@@ -103,6 +104,7 @@ public class MainUtil { |
103 | 104 | private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder() |
104 | 105 | .followRedirects(HttpClient.Redirect.NORMAL) |
105 | 106 | .build(); |
| 107 | + private static final int LZ4_DEFAULT_SEED = 0x9747b28c; |
106 | 108 |
|
107 | 109 | public static List<String> filter(String prefix, List<String> suggestions) { |
108 | 110 | if (prefix.isEmpty()) { |
@@ -299,14 +301,27 @@ public static FaweOutputStream getCompressedOS(OutputStream os, int amount, int |
299 | 301 | LZ4Factory factory = LZ4Factory.fastestInstance(); |
300 | 302 | int fastAmount = 1 + ((amount - 1) % 3); |
301 | 303 | for (int i = 0; i < fastAmount; i++) { |
302 | | - os = new LZ4BlockOutputStream(os, buffer, factory.fastCompressor()); |
| 304 | + // (syncFlush can't be provided without providing explicit Checksum instance) |
| 305 | + //noinspection resource - default LZ4 implementation doesn't close Checksum |
| 306 | + os = new LZ4BlockOutputStream( |
| 307 | + os, buffer, factory.fastCompressor(), |
| 308 | + XXHashFactory.fastestInstance().newStreamingHash32(LZ4_DEFAULT_SEED).asChecksum(), true |
| 309 | + ); |
303 | 310 | } |
304 | 311 | int highAmount = amount > 3 ? 1 : 0; |
305 | 312 | for (int i = 0; i < highAmount; i++) { |
306 | 313 | if (amount == 9) { |
307 | | - os = new LZ4BlockOutputStream(os, buffer, factory.highCompressor(17)); |
| 314 | + //noinspection resource - default LZ4 implementation doesn't close Checksum |
| 315 | + os = new LZ4BlockOutputStream( |
| 316 | + os, buffer, factory.highCompressor(17), |
| 317 | + XXHashFactory.fastestInstance().newStreamingHash32(LZ4_DEFAULT_SEED).asChecksum(), true |
| 318 | + ); |
308 | 319 | } else { |
309 | | - os = new LZ4BlockOutputStream(os, buffer, factory.highCompressor()); |
| 320 | + //noinspection resource - default LZ4 implementation doesn't close Checksum |
| 321 | + os = new LZ4BlockOutputStream( |
| 322 | + os, buffer, factory.highCompressor(), |
| 323 | + XXHashFactory.fastestInstance().newStreamingHash32(LZ4_DEFAULT_SEED).asChecksum(), true |
| 324 | + ); |
310 | 325 | } |
311 | 326 | } |
312 | 327 | os = new FastBufferedOutputStream(os, buffer); |
|
0 commit comments