Class CompressionUtils
java.lang.Object
com.bonitasoft.processbuilder.utils.CompressionUtils
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:
- Converts string to UTF-8 bytes
- Compresses using GZIP
- 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 Summary
Modifier and TypeMethodDescriptionstatic StringCompresses a string using GZIP compression and encodes it as Base64.static Stringdecompress(String compressedBase64) Decompresses a Base64-encoded GZIP-compressed string back to its original form.static doublegetCompressionRatio(String originalString, String compressedBase64) Calculates the compression ratio as a percentage.
-
Method Details
-
compress
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 nullIOException- if compression fails
-
decompress
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 formatIOException- if decompression fails (corrupted data, invalid GZIP format)
-
getCompressionRatio
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 stringcompressedBase64- The compressed Base64 string- Returns:
- Compression ratio as percentage (0-100), where lower is better
- Throws:
IllegalArgumentException- if either parameter is null
-