Java 25 FFM Binding for libdeflate
English | 中文
LibDeflate4J is a high-performance Java binding for libdeflate (a heavily optimized library for DEFLATE/zlib/gzip compression and decompression.) This project leverages Java 25's Foreign Function & Memory (FFM) API to provide native-speed compression/decompression with a clean Java API.
- High Performance: Direct native binding via Java FFM API, minimal overhead
- Modern Java: Uses Java 25 features including FFM API
- Java: JDK 25 or later
- Build Tools: Gradle 8.0+
- Native Compiler:
-
- Windows: MSVC (Visual Studio 2015+), MinGW, or Cygwin
-
- Linux: GCC 4.9+ or Clang 3.9+
-
- macOS: Xcode 8+ (Clang)
-
- CMake: 3.10+ (automatically invoked during build)
The version number consists of the main version of libdeflate and the project revision version, for example, 1.25.1 is the first revision using libdeflate v1.25.
We have not yet published this package to any repository, so you may need to clone this project and manually build it through Gradle.
import io.github.zrurf.*;
public class Example {
public static void main(String[] args) {
// Compress data
byte[] data = "Hello, World!".getBytes();
try (Compressor compressor = Compressor.create(6)) {
byte[] compressed = compressor.deflateCompress(data);
// Decompress data
try (Decompressor decompressor = Decompressor.create()) {
byte[] decompressed = decompressor.deflateDecompress(compressed);
System.out.println(new String(decompressed)); // "Hello, World!"
}
}
// Calculate checksums
int adler32 = LibDeflate4J.adler32(data);
int crc32 = LibDeflate4J.crc32(data);
System.out.printf("Adler-32: %d, CRC-32: %d%n", adler32, crc32);
}
}# Clone the repository
git clone https://github.com/zrurf/libdeflate4j.git
cd libdeflate4j
# Build with Gradle (requires CMake and C compiler)
./gradlew build
# Run tests
./gradlew test
# Install to local Maven repository
./gradlew publishToMavenLocal- LibDeflate4J: Static utility methods for checksums and compression bounds
- Compressor: Compresses data using DEFLATE/zlib/gzip formats
- Decompressor: Decompresses data from DEFLATE/zlib/gzip formats
- Result: Enumeration of decompression result codes
- Memory: Utility for safe native memory management
- 0: No compression (fastest)
- 1-9: Increasing compression ratio (6 is default)
- 10-12: Maximum compression (slowest)
- DEFLATE: Raw DEFLATE format without headers
- zlib: RFC 1950 format with zlib headers
- gzip: RFC 1952 format with gzip headers
The build system automatically downloads and compiles libdeflate for the current platform:
| Platform | Library Format | Compiler |
|---|---|---|
| Windows | .dll |
MSVC/MinGW |
| Linux | .so |
GCC/Clang |
| macOS | .dylib |
Xcode command line tools |
Run the comprehensive test suite:
./gradlew test --enable-native-access=ALL-UNNAMED --enable-preview- Round-trip compression/decompression
- Checksum calculations
- Edge cases (empty data, large data)
- Multiple compression levels
Currently, only publishing to local Maven repositories is supported, and remote repositories are not yet supported.
- Publish to remote maven repository
This project is licensed under the MIT License.
See the LICENSE file for details.
- libdeflate by Eric Biggers and other contributors
- Java Foreign Function & Memory API team
- All contributors and testers