Class CompressionUtils

java.lang.Object
com.bonitasoft.processbuilder.utils.CompressionUtils

public final class CompressionUtils extends Object
Utility class for compressing and decompressing strings using GZIP compression and Base64 encoding.

This class provides methods to:

  • Compress strings (typically JSON) to reduce size for transmission
  • Decompress previously compressed strings back to original form

The compression process:

  1. Converts string to UTF-8 bytes
  2. Compresses using GZIP
  3. Encodes compressed bytes to Base64 for safe string transmission

Typical compression ratios for JSON data: 70-90% size reduction.

Since:
2026-02-12
Version:
1.0
Author:
Process-Builder Development Team
  • Method Details

    • compress

      public static String compress(String input) throws IOException
      Compresses a string using GZIP compression and encodes it as Base64.

      This method is particularly useful for compressing JSON strings or other text data before sending them over the network or storing them in a database.

      Example:

       String json = "{\"data\": \"large content...\"}";
       String compressed = CompressionUtils.compress(json);
       // compressed is now a Base64-encoded GZIP string, typically 70-90% smaller
       
      Parameters:
      input - The string to compress (must not be null)
      Returns:
      Base64-encoded GZIP-compressed string
      Throws:
      IllegalArgumentException - if input is null
      IOException - if compression fails
    • decompress

      public static String decompress(String compressedBase64) throws IOException
      Decompresses a Base64-encoded GZIP-compressed string back to its original form.

      This method reverses the compression performed by compress(String). The input must be a valid Base64-encoded GZIP string, otherwise decompression will fail.

      Example:

       String compressed = "H4sIAAAAAAAA/..."; // Base64 GZIP string
       String original = CompressionUtils.decompress(compressed);
       // original is now the decompressed string
       
      Parameters:
      compressedBase64 - The Base64-encoded GZIP-compressed string (must not be null)
      Returns:
      The decompressed original string
      Throws:
      IllegalArgumentException - if compressedBase64 is null or has invalid Base64 format
      IOException - if decompression fails (corrupted data, invalid GZIP format)
    • getCompressionRatio

      public static double getCompressionRatio(String originalString, String compressedBase64)
      Calculates the compression ratio as a percentage.

      This is a utility method for monitoring and logging compression effectiveness.

      Example:

       String original = "{\"data\": \"...\"}"; // 1000 bytes
       String compressed = CompressionUtils.compress(original);
       double ratio = CompressionUtils.getCompressionRatio(original, compressed);
       // ratio might be 15.5 (meaning compressed is 15.5% of original size)
       
      Parameters:
      originalString - The original uncompressed string
      compressedBase64 - The compressed Base64 string
      Returns:
      Compression ratio as percentage (0-100), where lower is better
      Throws:
      IllegalArgumentException - if either parameter is null