Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a good compression library for Java?

I need to compress portions of our application's network traffic for performance. I presume this means I need to stay away from some of the newer algorithms like bzip2, which I think I have heard is slower.

like image 556
skiphoppy Avatar asked Sep 24 '08 13:09

skiphoppy


People also ask

Which is the best compression algorithm?

The fastest algorithm, lz4, results in lower compression ratios; xz, which has the highest compression ratio, suffers from a slow compression speed.

What is compression in Java?

Object compression is done at the sender side and uncompressed them at the other end i.e receiver side. By this, we can improve the performance and can send and receive the objects in heavy quantity between two ends.

How do I compress a string in Java?

string compression in java can be performed using a ZLIB compression library. It offers some distinct features to effectively compress string data in java. Although the compression rate could vary based on the factors such as the amount of compression required, length of data and repetitions in string data.

What is Commons compress used for?

Apache Commons Compress software defines an API for working with compression and archive formats.


2 Answers

You can use Deflater/Inflater which is built into the JDK. There are also GZIPInputStream and GZIPOutputStream, but it really depends on your exact use.

Edit:

Reading further comments it looks like the network taffic is HTTP. Depending on the server, it probably has support for compression (especially with deflate/gzip). The problem then becomes on the client. If the client is a browser it probably already supports it. If your client is a webservices client or an http client check the documentation for that package to see if it is supported.

It looks like jakarta-commons httpclient may require you to manually do the compression. To enable this on the client side you will need to do something like

.addRequestHeader("Accept-Encoding","gzip,deflate");
like image 193
Steve g Avatar answered Oct 07 '22 03:10

Steve g


If the network traffic is going over HTTP, most of the various web servers/servlet containers support for negotiated zipping, e.g., mod_deflate for Apache.

like image 28
Hank Gay Avatar answered Oct 07 '22 02:10

Hank Gay