lzma java sdk,如何使用LZMA SDK在Java中压缩/解压缩

http://www.7-zip.org/sdk.html

This site provide a LZMA SDK for compress/decompress files, I would like to give it a shot but I am lost.

Anyone got experience on this? Or a tutorial? Thanks.

解决方案

Short answer: don't

The 7zip sdk is old and unmaintained and it's just a JNI wrapper around the C++ library. A pure Java implementation on a modern JVM (1.7+) is as fast as a C++ one and has less dependecies and portability issues.

XZ is a file format based on LZMA2 (an improved version of LZMA)

The guys that invented the XZ format build a pure java implementation of the XZ archive compression / extraction algorithms

The XZ file format is designed to store 1 file only. Thus you need to zip/tar the source folder(s) into a single uncompressed file first.

Using the java library is as easy as this:

FileInputStream inFile = new FileInputStream("src.tar");

FileOutputStream outfile = new FileOutputStream("src.tar.xz");

LZMA2Options options = new LZMA2Options();

options.setPreset(7); // play with this number: 6 is default but 7 works better for mid sized archives ( > 8mb)

XZOutputStream out = new XZOutputStream(outfile, options);

byte[] buf = new byte[8192];

int size;

while ((size = inFile.read(buf)) != -1)

out.write(buf, 0, size);

out.finish();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值