java.util.zip.ZipFile doesn't take InputStream as constructor

  • Thread starter Geoffrey Gallaway
  • Start date
G

Geoffrey Gallaway

Hello,

I'm trying to arbitrarily pull files out of a multi-100-meg zip file.
The zip file has been encrypted so I can't simply give ZipFile()'s
constructor the filename. I need to pass the zip file through a cipher
object which can give me an inputstream but ZipFile doesn't have a
constructor that takes anything but a file/filename. I could use
ZipInputStream but that requires me to spin through getNextEntry
looking for the ZipEntry with the right filename which takes too long
on a large zip file. Zip files have indexes which ZipFile.getEntry()
probably uses to quickly seek to the correct location in the zip file
when ZipFile.getInputStream() is called.

How can I get quick, arbitrary access to a zip file when the underlying
data isn't a file itself but an inputstream?


Thanks,
Geoffeg
 
C

Chris Uppal

Geoffrey said:
How can I get quick, arbitrary access to a zip file when the underlying
data isn't a file itself but an inputstream?

You can't.

In the first place, decoding the ZIP file format requires (if you don't want to
fall back on a sequential scan) arbitrary random access in the data stream, and
java.io.InputStream does not provide that. (A serious flaw in the streams
framework IMO -- but that's another story.)

In the second place, even if there were interfaces available so that you could
supply the Zip implementation with a "stream" that supported true random
access, you wouldn't be able (I hope!) to supply one. Since your data is
encoded, the coding would need to be such that you could decode an arbitrary
block in more-or-less constant time -- and that's not a good property for an
ecryption algorithm to have ;-)

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top