暂时没有打开提取从归档文件 [英] Open a file from archive without temporary extraction

查看:198
本文介绍了暂时没有打开提取从归档文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在归档浏览应用程序,允许用户浏览存档内容,提取档案和preVIEW存档内的文件。我使用 java.util.zip API。为preVIEW文件我暂时解压缩,打开它作为一个通常的现有文件。正如你可能知道,这不是因为它不会preVIEW文件,如果没有足够的空间来创建一个临时抽取一个不错的办法。是否有过 ZipInputStream 活动来打开它作为一个文件一个可行的解决方案?是否有另一种解决这一问题?先谢谢了。

Right now I'm working on an archive browsing application that lets users navigate through archive contents, extract the archives and preview the files inside the archive. I'm using java.util.zip API. To preview a file I'm extracting it temporarily and opening it as a usual existing file. As you may understand, that's not a good approach since it won't preview files if there's not enough space to make a temporary extraction. Is there a working solution for passing ZipInputStream to an Activity to open it as a file? Is there another workaround for this problem? Thanks in advance.

推荐答案

在原则上,你可以创建一个的ContentProvider 供应了 ZipInputStream

In principle, you could create a ContentProvider that serves up the ZipInputStream.

此示例项目我演示了如何创建一个的ContentProvider 支持中openFile()使用由 ParcelFileDescriptor.createPipe创建了一个管道()来服务于一个文件。 createPipe()返回 ParcelFileDescriptors 一对(两个元素的数组)再presenting管的两端。您可以使用第二个元素从​​数组中通过写一个的OutputStream ; 中openFile()返回的第一个元素从数组中由机器人传递给调用进程。来电者会使用 openInputStream()来读取你通过管道传输。

In this sample project I demonstrate how to create a ContentProvider supporting openFile() that uses a pipe created by ParcelFileDescriptor.createPipe() to serve up a file. createPipe() returns a pair (two-element array) of ParcelFileDescriptors representing the ends of the pipe. You use the second element out of the array to write to via an OutputStream; openFile() returns the first element out of the array to be passed by Android to the calling process. The caller would use openInputStream() to read in what you transfer via the pipe.

在我的情况,我送的,我得到一个的InputStream 通过 AssetManager 的资产。在你的情况,你会用你的 ZipInputStream

In my case, I am sending an asset on which I get an InputStream via AssetManager. In your case, you would use your ZipInputStream.

请注意,我的示例项目假定它正在运行,有一个PDF浏览器的设备上,因为它是服务于PDF出资产,并试图通过 startActivity()

Note that my sample project assumes it is being run on a device that has a PDF viewer, since it is serving a PDF out of assets and trying to open it via startActivity().

这篇关于暂时没有打开提取从归档文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆