rmahindra123 commented on a change in pull request #3128:
URL: https://github.com/apache/hudi/pull/3128#discussion_r669296725



##########
File path: 
hudi-common/src/main/java/org/apache/hudi/common/util/collection/BitCaskDiskMap.java
##########
@@ -399,4 +419,47 @@ public int compareTo(ValueMetadata o) {
       return Long.compare(this.offsetOfValue, o.offsetOfValue);
     }
   }
+
+  private static class CompressionHandler implements Serializable {
+    private static final int DISK_COMPRESSION_INITIAL_BUFFER_SIZE = 1048576;
+    private static final int DECOMPRESS_INTERMEDIATE_BUFFER_SIZE = 8192;
+
+    // Caching ByteArrayOutputStreams to avoid recreating it for every 
operation
+    private final ByteArrayOutputStream compressBaos;
+    private final ByteArrayOutputStream decompressBaos;
+    private final byte[] decompressIntermediateBuffer;
+
+    CompressionHandler() {
+      compressBaos = new 
ByteArrayOutputStream(DISK_COMPRESSION_INITIAL_BUFFER_SIZE);
+      decompressBaos = new 
ByteArrayOutputStream(DISK_COMPRESSION_INITIAL_BUFFER_SIZE);
+      decompressIntermediateBuffer = new 
byte[DECOMPRESS_INTERMEDIATE_BUFFER_SIZE];
+    }
+
+    private byte[] compressBytes(final byte[] value) throws IOException {
+      compressBaos.reset();
+      Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
+      DeflaterOutputStream dos = new DeflaterOutputStream(compressBaos, 
deflater);
+      try {
+        dos.write(value);
+      } finally {
+        dos.close();
+        deflater.end();
+      }
+      return compressBaos.toByteArray();
+    }
+
+    private byte[] decompressBytes(final byte[] bytes) throws IOException {
+      decompressBaos.reset();
+      InputStream in = new InflaterInputStream(new 
ByteArrayInputStream(bytes));
+      try {
+        int len;
+        while ((len = in.read(decompressIntermediateBuffer)) > 0) {

Review comment:
       yes, it is just used to read from input stream and write to the output 
stream. also ran this by Vinoth, and he is fine with this.




-- 
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.

To unsubscribe, e-mail: [email protected]

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


Reply via email to