What's a good compression library for Java?

前端 未结 3 1876
故里飘歌
故里飘歌 2020-12-06 13:57

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, wh

3条回答
  •  鱼传尺愫
    2020-12-06 14:30

    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");
    

提交回复
热议问题