File with zip files displayed in memory in Java

Here is the problem I'm trying to solve:

I have about 100 binary files (only 158 KB and approximately the same size +/- 50% from each other). I need to selectively analyze only some of these files (in the worst case, there may be 50, in other cases only 1 - 5). By the way, this is on an Android device.

What is the fastest way to do this in Java?

One way can combine everything into one file, and then use the file to access each individual file. Thus, you need to open the file only once, and this is usually slow. However, in order to know where each file should be some table at the beginning of the file, which can be generated using a script, but the files will also need to be indexed in the table in the order in which they were combined, so file search should not have would work hard (correct me if I am wrong).

It would be best to display a memory card, and then the table would not have to be sorted by concatenation order, because the memory-mapped file would have random access (correct me again if I am wrong).

Creating this table would not be necessary if ZIP compression were used, since zip compression already makes the table. In addition, all files do not have to be combined. I could archive the directory and then access each individual file by their entries in the zip file. The problem is resolved.

Except that the zip file is not displayed in memory, it will be slower to read, since system calls are slower than direct memory access (correct me if I am wrong). So, I came to the conclusion that the best solution would be to use a zip archive with memory mapping.

However, ZipFile records return an InputStream to read the contents of the record. And MappedByteBuffer requires a RandomAccessFile that accepts the file name as input rather than InputStream .

Is there a zip file in the memory card for quick reading? Or is there another solution to this problem when reading files?

thanks

EDIT: I tested the speed of opening, closing, and parsing files, here are the statistics I found:

Number of Files: 25 (24 for parse because garbage collection interrupted timing)
Total Open Time: 72ms
Total Close Time: 1ms
Total Parse Time: 515ms

(this is distorted in favor of Parse because Parse is missing a file)
%Total time Open takes: 12%
%Total time Close takes: 0.17%
%Total time Parse takes: 88%

Avg time Open takes per file: 2.88ms
Avg time Close takes per file: 0.04ms
Avg time Parse takes per file: 21.46ms

+6
java android file-io zip
source share
1 answer

I would use a simple api like RandomAccessFile and go to the problem if you really need to.

Change I did not know about MappedByteBuffer . It seems like a way. Why not do it with separate files, and then think about combining them later?

+1
source share

All Articles