Java bindings for Brotli: a new compression algorithm for the internet.
🚨 Experimental 🚀
I've build a second experiment to let a patched Tomcat server make use of jbrotli.
Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling, with a compression ratio comparable to the best currently available general-purpose compression methods. It is similar in speed with deflate but offers more dense compression.
It was developed by Google and released in September 2015 via this blog post: Introducing Brotli: a new compression algorithm for the internet
NativeLoader.loadLibrary("brotli");
byte[] inBuf = "Brotli: a new compression algorithm for the internet. Now available for Java!".getBytes();
byte[] compressedBuf = new byte[2048];
BrotliCompressor compressor = new BrotliCompressor();
int outLength = compressor.compress(Brotli.DEFAULT_PARAMETER, inBuf, compressedBuf);NativeLoader.loadLibrary("brotli");
byte[] inBuf = "Brotli: a new compression algorithm for the internet. Now available for Java!".getBytes();
boolean doFlush = true;
BrotliStreamCompressor streamCompressor = new BrotliStreamCompressor(Brotli.DEFAULT_PARAMETER);
byte[] compressed = streamCompressor.compress(inBuf, doFlush);- Java JDK 8
- CMake v3.0+
- C++ compiler tool chain (see below)
As this project is under development. The goal is to provide native libraries for Linux, Windows and OSX in 32bit and 64bit. Currently the following platforms and architectures are tested:
- Windows 10, 64bit
- compiler tool chains
- [ok] NMake 32bit+64bit
- [ok] MS Visual Studio 2010 32bit+64bit
- [ok] MS Visual Studio 2013 32bit+64bit
- [ok] MS Visual Studio 2015 32bit+64bit
- [fail] mingw 64bit
- compiler tool chains
- OSX El Capitan v10.11.1
- compiler tool chains:
- [ok] Xcode, AppleClang 7.0.2
- compiler tool chains:
- Linux, Ubuntu 14.x, 64bit
- compiler tool chains:
- [ok] GNU CC 4.9.2
- compiler tool chains:
The jbrotli-native Maven modules are configured to automatically be activated on your platform. E.g. on Windows with a 64bit JDK the module 'win32-x86-64' will be picked up. If you want to build the 32bit version on Windows, you also need the 32bit JDK installed and to setup different ENV variables for your Windows SDK (or Visual Studio). See build.bat files for more details.
cd jbrotli-native
mvn packageEach native module contains a small build script. E.g. for Windows 64bit, you may use this ...
cd jbrotli-native/win32-x86-64
build.batThis is only needed when native method signatures change.
mvn -pl jbrotli compile
javah -v -d jbrotli-native/src/main/cpp -classpath jbrotli/target/classes de.bitkings.jbrotli.BrotliCompressor de.bitkings.jbrotli.BrotliDeCompressor de.bitkings.jbrotli.BrotliStreamCompressor de.bitkings.jbrotli.BrotliStreamDeCompressor de.bitkings.jbrotli.BrotliErrorExample for Linux 64bit
cd jbrotli-native/linux-x86-64
mvn install
cd ../..
mvn -pl jbrotli-native install
mvn -pl jbrotli package
java -jar jbrotli/target/jbrotli-0.2.0-SNAPSHOT.jarSome results are documented in this spreadsheet https://docs.google.com/spreadsheets/d/1y3t_NvXrD58tKCXMvNC49EtxBMQQOE_8SPQLS6c1cJo/edit?usp=sharing