开发者

android: fast way do deal with comprssed strings

开发者 https://www.devze.com 2023-03-06 05:15 出处:网络
I have a number of compressed String(1.5M each) stored in a file. I need to read them out, and do some computation on them. Basically, here is what I did:

I have a number of compressed String(1.5M each) stored in a file. I need to read them out, and do some computation on them. Basically, here is what I did:

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

The only problem i开发者_StackOverflow中文版s, the performance of the code is quite slow in general, so I am thinking 2 options:

  1. to use NIO to map the compressed file into memory, and do the above on the memory compressed file(I heard that this may be achievable, but I have no idea if it really is)

  2. Instead of storing objects, I could just store binary compressed version of the text and then read the text, I heard that it may be fast then ObjectInputStream.

Anyone knows a way of achieving the above options? or is there a better way, thanks a lot.


You might be interested in using DeflatorOutputStream and InflatorInputStream see Fast compression in Java?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号