Class CompressionUtils
java.lang.Object
io.fluxcapacitor.common.serialization.compression.CompressionUtils
Utility class for compressing and decompressing byte arrays using common compression algorithms.
Supports multiple algorithms including:
CompressionAlgorithm.LZ4
– fast compression optimized for speedCompressionAlgorithm.GZIP
– standard GZIP format for interoperabilityCompressionAlgorithm.NONE
– pass-through mode (no compression)
LZ4 Support
When compressing with LZ4, the output includes a 4-byte prefix that encodes the length of the original (uncompressed) data. This prefix is required during decompression.GZIP Support
GZIP compression and decompression are compatible with standard ZIP tools. If aZipException
is thrown during GZIP decompression (e.g. data is not compressed), the original input is returned as-is.
Usage
byte[] input = ...;
byte[] compressed = CompressionUtils.compress(input, CompressionAlgorithm.GZIP);
byte[] restored = CompressionUtils.decompress(compressed, CompressionAlgorithm.GZIP);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
compress
(byte[] uncompressed) Compresses the given byte array usingCompressionAlgorithm.LZ4
by default.static byte[]
compress
(byte[] uncompressed, @NonNull CompressionAlgorithm algorithm) Compresses the given byte array using the specified compression algorithm.static byte[]
decompress
(byte[] compressed) Decompresses the given byte array usingCompressionAlgorithm.LZ4
by default.static byte[]
decompress
(byte[] compressed, @NonNull CompressionAlgorithm algorithm) Decompresses the given byte array using the specified algorithm.
-
Constructor Details
-
CompressionUtils
public CompressionUtils()
-
-
Method Details
-
compress
public static byte[] compress(byte[] uncompressed) Compresses the given byte array usingCompressionAlgorithm.LZ4
by default.- Parameters:
uncompressed
- the data to compress- Returns:
- the compressed byte array
-
compress
public static byte[] compress(byte[] uncompressed, @NonNull @NonNull CompressionAlgorithm algorithm) Compresses the given byte array using the specified compression algorithm.- Parameters:
uncompressed
- the data to compressalgorithm
- the compression algorithm to use- Returns:
- the compressed byte array
-
decompress
public static byte[] decompress(byte[] compressed) Decompresses the given byte array usingCompressionAlgorithm.LZ4
by default.- Parameters:
compressed
- the compressed data- Returns:
- the original (decompressed) byte array
-
decompress
public static byte[] decompress(byte[] compressed, @NonNull @NonNull CompressionAlgorithm algorithm) Decompresses the given byte array using the specified algorithm.- Parameters:
compressed
- the compressed dataalgorithm
- the compression algorithm to apply- Returns:
- the original (decompressed) byte array
-