liyafan82 commented on a change in pull request #9769:
URL: https://github.com/apache/arrow/pull/9769#discussion_r601039259



##########
File path: 
java/compression/src/main/java/org/apache/arrow/compression/Lz4CompressionCodec.java
##########
@@ -38,109 +36,39 @@
 /**
  * Compression codec for the LZ4 algorithm.
  */
-public class Lz4CompressionCodec implements CompressionCodec {
+public class Lz4CompressionCodec extends AbstractCompressionCodec {
 
-  @Override
-  public ArrowBuf compress(BufferAllocator allocator, ArrowBuf 
uncompressedBuffer) {
-    Preconditions.checkArgument(uncompressedBuffer.writerIndex() <= 
Integer.MAX_VALUE,
-        "The uncompressed buffer size exceeds the integer limit");
-
-    if (uncompressedBuffer.writerIndex() == 0L) {
-      // shortcut for empty buffer
-      ArrowBuf compressedBuffer = 
allocator.buffer(CompressionUtil.SIZE_OF_UNCOMPRESSED_LENGTH);
-      compressedBuffer.setLong(0, 0);
-      
compressedBuffer.writerIndex(CompressionUtil.SIZE_OF_UNCOMPRESSED_LENGTH);
-      uncompressedBuffer.close();
-      return compressedBuffer;
-    }
-
-    try {
-      ArrowBuf compressedBuffer = doCompress(allocator, uncompressedBuffer);
-      long compressedLength = compressedBuffer.writerIndex() - 
CompressionUtil.SIZE_OF_UNCOMPRESSED_LENGTH;
-      if (compressedLength > uncompressedBuffer.writerIndex()) {
-        // compressed buffer is larger, send the raw buffer
-        compressedBuffer.close();
-        compressedBuffer = CompressionUtil.packageRawBuffer(allocator, 
uncompressedBuffer);
-      }
-
-      uncompressedBuffer.close();
-      return compressedBuffer;
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
-  }
-
-  private ArrowBuf doCompress(BufferAllocator allocator, ArrowBuf 
uncompressedBuffer) throws IOException {
+  protected ArrowBuf doCompress(BufferAllocator allocator, ArrowBuf 
uncompressedBuffer) {

Review comment:
       Nice catch. Thank you.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to