Skip to content

Commit

Permalink
Revert "change: compress data in one call"
Browse files Browse the repository at this point in the history
This reverts commit 01afb60.
  • Loading branch information
ishland committed Oct 4, 2024
1 parent b53984f commit 3eefeff
Showing 1 changed file with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.util.Queue;
Expand Down Expand Up @@ -347,23 +345,19 @@ private void writeChunk(long pos, Either<NbtCompound, byte[]> nbt) {
ChunkCompressionFormat finalCompressionFormat = compressionFormat;
final CompletableFuture<Void> future = CompletableFuture.supplyAsync(() -> {
try {
ByteArrayOutputStream uncompressedStream = new ByteArrayOutputStream();
try (DataOutputStream dataOutputStream = new DataOutputStream(uncompressedStream)) {
if (nbt.left().isPresent()) {
NbtIo.writeCompound(nbt.left().get(), dataOutputStream);
} else {
dataOutputStream.write(nbt.right().get());
}
}
final RawByteArrayOutputStream out = new RawByteArrayOutputStream(8096);
// TODO [VanillaCopy] RegionFile.ChunkBuffer
out.write(0);
out.write(0);
out.write(0);
out.write(0);
out.write(finalCompressionFormat.getId());
try (OutputStream out1 = finalCompressionFormat.wrap(out)) {
uncompressedStream.writeTo(out1);
try (DataOutputStream dataOutputStream = new DataOutputStream(finalCompressionFormat.wrap(out))) {
if (nbt.left().isPresent()) {
NbtIo.writeCompound(nbt.left().get(), dataOutputStream);
} else {
dataOutputStream.write(nbt.right().get());
}
}
return out;
} catch (Throwable t) {
Expand Down

0 comments on commit 3eefeff

Please sign in to comment.