Java bindings for Brotli: a new compression algorithm for the internet.
jbrotli provides platform dependant bindings for Google's brotli library. Thus each target platform which is provided here was compiled and tested for the following operating systems and architectures.
- Windows 7 or newer, x86 64bit
- Windows 7 or newer, x86 32bit
- Linux, x86 64bit
- Raspberry Pi (Linux), ARMv6 32bit (hardware floating point)
With version 0.5.0 the compatibility for the Linux binaries was increased.
This is a pre-condition, to enable brotli compression in Hadoop, [HADOOP-13126](https://issues.apache.org/jira/browse/HADOOP-13126)
With version 0.4.0 the Raspberry PI binaries where added as supported platform.
For easier adoption of Brotli, there is now a 'BrotliServletFilter' available.
Have a look at 'jbrotli-examples' on how to use it in Tomcat, Spring Boot or Dropwizard.
This 0.4.0 release is bundled with the LATEST (un-released) version of brotli,
because it contains a security fix CVE-2016-1968. The latest Google brotli-release 0.3.0
is still vulnerable to this issue.
The problem with the crashing JVM is solved: it revealed itself as a memory leak in the
OutputStream class ;-)
Also high throughput and concurrent benchmarks are now running perfectly fine.
Monitoring with jConsole or jVisualVM shows that e.g. the BrotliServletFilter behaves
on par with GZIP compression in e.g. Tomcat web server.
When I did high throughput and highly concurrent benchmarks with the HTTP servers (see below),
I observed peak memory usages over 32GByte, which killed my JVM. I've searched for memory leaks,
but couldn't found any orphan objects after comparing heap dumps.
Unfortunately there isn't that much documentation on memory usage available. Which makes it difficult
to understand why there are such peaks and if these are "normal".
I don't recommend to use jbrotli in projects with many and highly concurrent compression tasks.
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
jbrotli releases are available at bintray
In order to use, simply add these lines to your project's pom.xml
<dependencies>
<dependency>
<groupId>org.meteogroup.jbrotli</groupId>
<artifactId>jbrotli</artifactId>
<version>0.5.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>bintray-nitram509-jbrotli</id>
<name>bintray</name>
<url>http://dl.bintray.com/nitram509/jbrotli</url>
</repository>
</repositories>
jbrotli's pom.xml will automatically select the native library,
depending on your platform's operating system family and arch type (Java property os.arch).
For a list of supported platforms, look for released jbrotli-native-*
artifacts at
jbrotli's bintray repository.
In order to use BrotliServletFilter, simply add these lines to your project's pom.xml
<dependencies>
<dependency>
<groupId>org.meteogroup.jbrotli</groupId>
<artifactId>jbrotli-servlet</artifactId>
<version>0.5.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>bintray-nitram509-jbrotli</id>
<name>bintray</name>
<url>http://dl.bintray.com/nitram509/jbrotli</url>
</repository>
</repositories>
Then finally activate the filter in your web.xml
<filter>
<filter-name>BrotliFilter</filter-name>
<filter-class>org.meteogroup.jbrotli.servlet.BrotliServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>BrotliFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
See full example at jbrotli-examples/simple-web-app
Enabling your Spring Boot or Dropwizard microservice
Enabling one of the famous microservice frameworks is very easy. Just have a look a the examples ...
BrotliLibraryLoader.loadBrotli();
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);
BrotliLibraryLoader.loadBrotli();
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.compressBuffer(inBuf, doFlush);
Some results are documented in this spreadsheet https://docs.google.com/spreadsheets/d/1y3t_NvXrD58tKCXMvNC49EtxBMQQOE_8SPQLS6c1cJo/edit?usp=sharing
If you want to compile & test this library yourself, please follow this guideline.