我正在Java中尝试xz压缩。使用xz 1.5压缩库、commons io 2.4库和commons compress 1.8.1库。我试图运行下面的代码,这给了我非常不一致的结果。超过 70% 的文本,低于 0.1% 的音频和视频文件(1-压缩/原始 * 100)。我在每次压缩之前都在制作一个 tarball。这应该只适用于文本文件吗?
package makexz;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.compress.compressors.CompressorOutputStream;
import org.apache.commons.compress.compressors.CompressorStreamFactory;
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
import org.apache.commons.compress.utils.IOUtils;
public class MakeXZ {
public static void main(String[] args) throws FileNotFoundException, IOException, Exception {
FileOutputStream dest = new FileOutputStream("C://TARDUMP//XZ//newvid.tar.xz");
CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.XZ, dest);
String input = "C://TARDUMP//newvid.tar";
IOUtils.copy(new FileInputStream(input), cos);
cos.close();
}
}