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

lzma java sdk,如何使用LZMA SDK在Java中压缩/解压缩http://www.7-zip.org/sdk.htmlThissiteprovideaLZMASDKforcompress/decompressfiles,IwouldliketogiveitashotbutIamlost.Anyonegotexperienceonthis?Oratutorial?Thanks.解决方案Shortans…

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

今天的文章lzma java sdk,如何使用LZMA SDK在Java中压缩/解压缩分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/25186.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注