Search code examples
javajava-native-interface7ziplzma

Is there a good way to handle *fast* compression to LZMA in Java?


The native Java LZMA SDK provided by the 7-Zip author works, but is not nearly fast enough for my needs. The high level implementation just doesn't seem to be able to handle the low level-work needed by the algorithm.

I've found 7-Zip-JBinding, which implements a JNI cover over the C++ dll which ships with 7-Zip. This handles decompression at a reasonable speed, but it's in beta and doesn't currently support compression.

Anyway, my question is two-part:

  1. Is my assumption that a DLL wrapper is my best bet for a fast Java implementation?
  2. If so, is there a pre-existing project I should be looking at or do I have to write something from the ground up?

Solution

  • It might not be an option for you, but I've had excellent success with simply executing an external 7z process using ProcessBuilder. Using LZMA2 and lowering compression level dramatically sped up compression time too. There are portability issues of course.

    You might want to check out XZ for Java. XZ uses LZMA2 compression, but has a different format better suited for Unix environments. The latest 7zip should be able to extract .XZ archives.