0

I have to pass an InputStream as a parameter to a 3rd party library, which will read the complete contents from the InputStream and do its job.

My problem is, some of my files are Zip files - with more than one ZipEntry. From what I understand, one can read one zipEntry at a time and then do a zipInputStream.getNextEntry() and then again read and so on. But, the 3rd party library doesn't understand this and expects a single InputStream. All the zipEntries of a zip file should be available as a single inputStream.

Please enlighten me as to how to do it. I cannot use ZipFile as the file is not stored locally (in a different server). I also cannot read all zipEntries and construct a ByteArrayOutputStream or a string as the files can be very big and that will spike memory usage.

I want a way to let one inputStream read from multiple zip entries of a single zip file transparantly.

thanks in advance, Prasanna

  • It would be helpful to tell us what 3rd party library you're using, I'm guessing SharpZipLib (http://www.icsharpcode.net/opensource/sharpziplib/) based on the types you mention in your question =) – Rob Aug 24 '10 at 12:01

1 Answers1

0

I'm no expert but I see two ways of doing what you are asking for:

While I wouldn't call it the most efficient way, the fairly foolproof method is to write them all to a buffer and then use that buffer to feed an inputstream. You could look into using a ByteArrayOutputStream, feed it your ZipEntries, and then create a ByteArrayInputStream with the same buf

Alternatively the SequenceInputStream sounds like it does what you are after, but I've not had a chance to look into it in much detail.

K.Barad

K.Barad
  • 1,006
  • 3
  • 14
  • 20