diff --git a/src/main/java/io/usethesource/vallang/io/binary/util/DirectZstdInputStream.java b/src/main/java/io/usethesource/vallang/io/binary/util/DirectZstdInputStream.java index 8505ba27..efa71635 100644 --- a/src/main/java/io/usethesource/vallang/io/binary/util/DirectZstdInputStream.java +++ b/src/main/java/io/usethesource/vallang/io/binary/util/DirectZstdInputStream.java @@ -28,7 +28,11 @@ protected ByteBuffer refill(ByteBuffer torefill) throws IOException { private static ByteBuffer constructDecompressedBuffer(ByteBufferInputStream oriStream) { int compressedSize = oriStream.getByteBuffer().remaining(); - ByteBuffer result = DirectByteBufferCache.getInstance().get(Math.min(compressedSize * 2, ZstdDirectBufferDecompressingStream.recommendedTargetBufferSize())); + int bufferSize = ZstdDirectBufferDecompressingStream.recommendedTargetBufferSize(); + if (bufferSize > compressedSize) { + bufferSize = Math.min(compressedSize * 2, bufferSize); + } + ByteBuffer result = DirectByteBufferCache.getInstance().get(bufferSize); result.limit(0); // delay compression for first read return result; }