Skip to content

BuildAPE/jbrotli

Repository files navigation

jBrotli

Java bindings for Brotli: a new compression algorithm for the internet.

License

License

Status of this project

🚨 Experimental 🚀

Example usage - Tomcat

I've build a second experiment to let a patched Tomcat server make use of jbrotli.

About Brotli

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

Example compression code snippet

Example of regular BrotliCompressor with custom dictionary
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);
Example of BrotliStreamCompressor using default dictionary
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);

Building this library

Requirements

Supported platforms and architecture

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
  • OSX El Capitan v10.11.1
    • compiler tool chains:
      • [ok] Xcode, AppleClang 7.0.2
  • Linux, Ubuntu 14.x, 64bit
    • compiler tool chains:
      • [ok] GNU CC 4.9.2

Build native libs

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.

automatically for your platform

cd jbrotli-native
mvn package

manual

Each native module contains a small build script. E.g. for Windows 64bit, you may use this ...

cd jbrotli-native/win32-x86-64
build.bat

Prepare JNI header files

This 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.BrotliError

Run benchmark

Example 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.jar

Performance benchmark results

Some results are documented in this spreadsheet https://docs.google.com/spreadsheets/d/1y3t_NvXrD58tKCXMvNC49EtxBMQQOE_8SPQLS6c1cJo/edit?usp=sharing

About

Java bindings for Brotli: a new compression algorithm for the internet

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors