开发者

How do I read multiple ZipEntries through a single InputStream

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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜