Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reading files from ZIP in memory

803451Oct 6 2010 — edited Oct 6 2010
Hi,

I need to extract some files from a ZIP archive which will be in memory, accessed with an InputStream (ByteArray).

As ZIP files are likely to be large, I'd like to have some sort of "random access" in the way java.util.ZipFile does, allowing me to access any file directly without having to iterate through all the entries. Unfortunately, ZipFiles can only be constructed from physical Files, but mines will always be in memory, and I can't dump them to disk.

So I think ZipInputStream is the only way to go here, but it imposes me a sequential access to the entries. Maybe I could fully read the file for the first time and save zip entries' offsets in a hash table, but I find it difficult to later seek the ZipInputStream to extract the entries with its offsets and it seems going back (or resetting) is not possible in this kind of streams.

Any idea? Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 3 2010
Added on Oct 6 2010
3 comments
2,162 views