From 82ae81c7afdbe45f90c124b1be2822617ea12164 Mon Sep 17 00:00:00 2001 From: iceBear67 Date: Sun, 28 Sep 2025 09:19:09 +0800 Subject: [PATCH] minor fixes --- .../main/java/io/ib67/sfcraft/bundler/BundleWriter.java | 8 +++++--- .../java/io/ib67/sfcraft/bundler/region/RegionParser.java | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bundler/src/main/java/io/ib67/sfcraft/bundler/BundleWriter.java b/bundler/src/main/java/io/ib67/sfcraft/bundler/BundleWriter.java index ecc5290..ee6f4b8 100644 --- a/bundler/src/main/java/io/ib67/sfcraft/bundler/BundleWriter.java +++ b/bundler/src/main/java/io/ib67/sfcraft/bundler/BundleWriter.java @@ -24,6 +24,7 @@ public class BundleWriter implements Closeable { protected final ByteBufAllocator allocator; protected final boolean allowReassemble; protected final int compressionLevel; + protected final boolean verbose; protected final Path relativeRoot; protected final EntryOutputStream outputStream; @@ -35,12 +36,13 @@ public class BundleWriter implements Closeable { int maxWorkers, Path relativeRoot, OutputStream outputStream, - byte[] dictionary, ByteBufAllocator allocator + byte[] dictionary, ByteBufAllocator allocator, boolean verbose ) { this.allowReassemble = allowGunzip; this.compressionLevel = compressionLevel; this.relativeRoot = relativeRoot; this.allocator = allocator == null ? ByteBufAllocator.DEFAULT : allocator; + this.verbose = verbose; var zstdOut = new ZstdOutputStreamNoFinalizer(outputStream, compressionLevel); if (dictionary != null) { zstdOut.setDict(new ZstdDictCompress(dictionary, compressionLevel)); @@ -151,11 +153,11 @@ public class BundleWriter implements Closeable { @SneakyThrows private void writeReassembleInMem(Path path) { if (!"region".equals(path.getParent().toString()) && !path.toString().endsWith(".mca")) { - System.out.println("Mismatch " + path + ", parent: " + path.getParent()); + if(verbose) System.out.println("Mismatch " + path + ", parent: " + path.getParent()); writePlain(path); return; } - System.out.println("Reassembling " + path); + if(verbose) System.out.println("Reassembling " + path); var uncompressed = allocator.buffer(); var rPath = relativeRoot.toAbsolutePath().relativize(path.toAbsolutePath()); try (var out = new EntryOutputStream(new ByteBufOutputStream(uncompressed)); diff --git a/bundler/src/main/java/io/ib67/sfcraft/bundler/region/RegionParser.java b/bundler/src/main/java/io/ib67/sfcraft/bundler/region/RegionParser.java index b3dd8a4..b9063e0 100644 --- a/bundler/src/main/java/io/ib67/sfcraft/bundler/region/RegionParser.java +++ b/bundler/src/main/java/io/ib67/sfcraft/bundler/region/RegionParser.java @@ -24,8 +24,12 @@ public class RegionParser implements Closeable { if (size < 8192) throw new IOException("The region file " + file + " has been truncated"); if(size > 8388608 * 2) throw new IOException("The region file " + file + " is too large"); //todo bug source = allocator.buffer(size); + try (var fc = FileChannel.open(file, StandardOpenOption.READ)) { - while (source.writeBytes(fc, 0L, (int) size) > 0) ; + var toRead = size; + while(toRead > 0){ + toRead -= source.writeBytes(fc, 0L, (int) size); + } } }