如何DECOM preSS的XZ文件快在Java中? [英] How to decompress an XZ file faster in Java?

查看:167
本文介绍了如何DECOM preSS的XZ文件快在Java中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

85MB大小的我的SQLite数据库文件是使用XZ格式COM pressed其规模已减少到16MB。我用下面的code(以及 XZ对Java 提供了一个JAR)至$ DECOM p $ PSS它的Andr​​oid果冻豆:

My SQLite db file of size 85MB is compressed using XZ format and its size has been reduced to 16MB. I use the following code (and a JAR provided by XZ for Java) to decompress it in Android Jelly Bean:

try { 
    FileInputStream fin = new FileInputStream(path + "myFile.xz");
    BufferedInputStream in = new BufferedInputStream(fin);
    FileOutputStream out = new FileOutputStream(des + "myDecompressed");
    XZInputStream xzIn = new XZInputStream(in);
    final byte[] buffer = new byte[8192];
    int n = 0;
    while (-1 != (n = xzIn.read(buffer))) {
        out.write(buffer, 0, n);
    } 
    out.close();
    xzIn.close();
}
catch(Exception e) { 
    Log.e("Decompress", "unzip", e); 
}

在DECOM pression成功完成,但它需要两分多钟内完成。我觉得这是很长的,因为COM pressed文件只有16MB,并uncom pressed文件只有85MB。

The decompression is done successfully, but it takes more than two minutes to complete. I think this is very long because the compressed file is only 16MB and uncompressed file is only 85MB.

我不知道我是否做了一些错误的code或有一种方法,以加快这一DECOM pressing过程。

I wonder whether I have done something wrong with the code or there is a way to speed up this decompressing process.

推荐答案

我觉得没有什么可以做,以使这个速度更快。如果是服用2分钟DECOM preSS 16Mb的到85MB,有机会,大部分时间在实际DECOM pression花费,剩下的一个显著的部分是在实际的文件I / O ......在物理层。

I think that there is little you can do to make this faster. If it is taking 2 minutes to decompress 16Mb to 85Mb, the chances are that most of that time is spent in the actual decompression, and a significant part of the rest is in the actual file I/O ... at the physical level.

当然,没有什么明显的低效率有关code。您正在使用使用一个大的缓冲区的BufferedInputStream和解码/写读书。所以,你会做的I / O系统调用有效。 (添加的BufferedOutputStream 将没有任何区别,因为你已经从8192字节的缓冲区做大量的写操作。)

Certainly, there is nothing obviously inefficient about your code. You are reading using a BufferedInputStream and decoding / writing using a large buffer. So you will be doing the I/O syscalls efficiently. (Adding a BufferedOutputStream won't make any difference because you are already doing large writes from a 8192 byte buffer.)

我可以建议最好的是你配置您的code,看看那里的热点真的是。但我怀疑,你不会找到任何可以够得到改善,有所作为。

The best I can suggest is that you profile your code to see where the hotspots really are. But I suspect that you won't find anything that can be improved enough to make a difference.

我想去XZ因为它在我的情况,这在一定程度节省下载时间最好COM pression水平......(拉链,该文件的解压仅需约15秒!

I want to go for XZ because it has the best compression level in my case, which somewhat saves the downloading time... (with zip, the unzipping of this file takes only about 15 seconds!

那么,在DECOM pression额外的CPU时间,你支付使用COM pression算法手摇到最高的价格。你需要决定哪个是你的用户更重要的是:更快的下载速度,或更快DECOM pression数据库(安装?)

Well, extra CPU time in decompression is the price that you pay for using a compression algorithm cranked up to the max. You need to decide which is more important to your users: faster downloads, or faster decompression (installation?) of the database.

FWIW,ZIP DECOM pression可能是在本机库来实现,而不是在纯Java。这当然是Oracle / OpenJDK的JVM中。

FWIW, ZIP decompression is probably implemented in a native library, not in pure Java. It certainly is for Oracle / OpenJDK JVMs.

这篇关于如何DECOM preSS的XZ文件快在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆