问题描述
我从另一个源接收ZipInputStream,我需要将第一个条目的InputStream提供给另一个源。
I'm receiving a ZipInputStream from another source, and I need to provide the first entry's InputStream to another source.
我希望能够这样做没有在设备上保存临时文件,但我知道获取单个条目的InputStream的唯一方法是通过ZipFile.getInputStream(entry),因为我有一个ZipInputStream而不是ZipFile,这是不可能的。
I was hoping to be able to do this without saving a temp file on a device, however the only way I know of getting an InputStream for an individual entry is via ZipFile.getInputStream(entry) and since I have a ZipInputStream and not a ZipFile, that is not possible.
所以我拥有的最佳解决方案是
So the best solution I have is
- 将传入的InputStream保存到文件
- 读取文件为ZipFile
- 使用第一个条目的InputStream
- 删除临时文件。
- save incoming InputStream to a file
- read file as ZipFile
- use first entry's InputStream
- delete temp file.
推荐答案
想通:
完全有可能,调用ZipInputStream .getNextEntry()将InputStream定位在条目的开头,因此提供ZipInputStream相当于提供ZipEntry的InputStream。
it's entirely possible, the call to ZipInputStream.getNextEntry() positions the InputStream at the start of the entry and therefore supplying the ZipInputStream is the equivalent of supplying a ZipEntry's InputStream.
ZipInputStream是smart e没有处理条目的EOF下游,或者看起来如此。
the ZipInputStream is smart enough to handle the entry's EOF downstream, or so it seems.
p。
这篇关于是否有可能从zipinputstream获得zipentry的输入流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!