【问题标题】:android: fast way do deal with comprssed stringsandroid:处理压缩字符串的快速方法
【发布时间】:2011-08-25 20:18:45
【问题描述】:

我有许多压缩字符串(每个 1.5M)存储在一个文件中。我需要把它们读出来,并对它们做一些计算。基本上,这就是我所做的:

public static Object fetchRSFB(File inFile) {
    FileInputStream fis = null;
    ObjectInputStream ois = null;
    GZIPInputStream gs = null;
    Object result = null;
    try {
        fis = new FileInputStream(inFile);
        gs = new GZIPInputStream(fis);
        ois = new ObjectInputStream(gs);
        MyBWT.rankArray = (int[]) ois.readObject();
        String str= (String) ois.readObject();
        //do something with the string

唯一的问题是,代码的性能总体上很慢,所以我在考虑2个选项:

  1. 使用NIO将压缩文件映射到内存中,对内存压缩文件进行上述操作(听说可以实现,不知道是不是真的)

  2. 我可以不存储对象,只存储文本的二进制压缩版本,然后读取文本,听说可能比 ObjectInputStream 快。

有人知道实现上述选项的方法吗?或者有没有更好的方法,非常感谢。

【问题讨论】:

    标签: android performance text io nio


    【解决方案1】:

    您可能对使用DeflatorOutputStream and InflatorInputStream 感兴趣,请参阅Fast compression in Java?

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 2016-02-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多