J7zip在Android上 - 提取存档和清单内容 [英] J7zip on Android - Extracting From an Archive and Listing Contents

查看:212
本文介绍了J7zip在Android上 - 提取存档和清单内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的previous问题得到了关闭,没有建设性的。我编辑在那里,​​但没有看到它被关闭):

My previous question got closed as not constructive. I edited it there, but didn't see that it was closed ):

我在写这涉及到提取7z格式的应用程序。目前似乎没有任何原生支持,所以我在寻找第三方库或源$ C ​​$ C,我可以融入我的项目冒险了。

I'm writing an application that involves extracting 7z archives. There doesn't seem to be any native support, so I've ventured off in search of third-party libraries or source code I could integrate into my project.

我一直在努力实现 J7zip ,但都没有成功。

I have been trying to implement J7zip but have not been successful.

清单存档的内容不返回任何文件:

Listing contents of the archive returns no files:

12-24 13:36:44.216: I/System.out(18473): J7zip 4.43 ALPHA 2 (2 CPUs)
12-24 13:36:44.232: I/System.out(18473):   Date   Time   Attr         Size   Compressed  Name
12-24 13:36:44.232: I/System.out(18473): -------------- ----- ------------ ------------  ------------
12-24 13:36:44.240: I/System.out(18473): -------------- ----- ------------ ------------  ------------

不过,上市的Windows(使用7z.exe)的内容返回以下

However, listing the contents on windows (using 7z.exe) returns the following

7-Zip 9.22 beta  Copyright (c) 1999-2011 Igor Pavlov  2011-04-18

Listing archive: archive.7z

--
Path = archive.7z
Type = 7z
Method = LZMA
Solid = -
Blocks = 1
Physical Size = 183119
Headers Size = 122

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
                    .....       524288       182997  contents.txt
------------------- ----- ------------ ------------  ------------------------
                                524288       182997  1 files, 0 folders

提取失败,我有 因为它是一个长一点的logcat中。

Extracting fails, I have the logcat of that here since it's a bit longer.

似乎有一个IO问题就在这里,但我怀疑别的自上市以来,该归档不返回任何文件。

There seems to be an io problem here, but I'm suspecting something else since listing this archive returns no files.

有没有人有经验的提取和使用上市存档J7zip内容?

Does anyone have experience extracting and listing archive contents using J7zip?

推荐答案

这里有一些可能的解决方案。

There are a few possible solutions here.

我第一次试图通过启动交叉编译的7zip的jbinding项目。我安装了armeabi C和C ++编译器到我的机器,并试图构建项目。不幸的是,我无法建立,可以在Android项目中使用的二进制文件。我提到了与试图加载编译后的二进制文件jbinding早在论坛上发帖引起麻烦的库。

I first started by trying to cross-compile the 7zip jbinding project. I installed the armeabi c and c++ compilers onto my machine and attempted to build the project. Unfortunately, I was unable to build a binary that could be used in an Android project. I mentioned the libraries that were causing trouble with trying to load the compiled jbinding binaries back in the forum post.

我的下一个牵头正在实施p7z,J7zip( HTTP的Java移植:// sourceforge上。净/项目/的p7zip /文件/ J7Zip / )。实现这个是不是太糟糕,但我不得不修改code其中的j7z库将尝试写入SD卡(无根访问权限)的根。此端口行之有效的大部分,但提取包含许多类似的文件较大档案,或归档时会导致内存不足的错误。问题是该库试图为字典分配太多的内存(这将分配的全部提取内容的大小,即使你只是想提取一个文件)。因此,该库将不会在我的情况下工作,我不认为它会支持你正在使用的COM pression。

My next lead was implementing the java port of p7z, J7zip (http://sourceforge.net/projects/p7zip/files/J7Zip/). Implementing this wasn't too bad, except that I had to modify code where the j7z library would try to write to the root of the SD card (no root access). This port worked well for the most part, but would cause out of memory errors when extracting larger archives, or archives containing many similar files. The problem was the library was trying to allocate too much memory for the dictionary (it would allocate the size of all the extracted contents, even if you only wanted to extract one file). So this library would not work in my case, and I don't think it would support the compression you're working with.

最后,我来到了被称为这个看似死谷歌code项目andro7z( HTTP://$c$c.google.com/p/andro7z/ )。这code包含一个版本7zip的和非常,非常基本的JNI实现。当你第一次抓源头,都可以做的是打印的使用,但它给你一个很好的起点。我结束了学习,并修改它,所以我可以从档案中返回一个包含包含在存档中的文件名称的字符串数组,以及具体的提取物或所有文件。由于我是唯一的工作与7z压缩文件,我没有做它一个很优雅的实现,但它的作品。使用实际7zip的C / CPP人士表示出流妥善处理,不会尝试分配离谱字典大小。

And finally, I arrived at this seemingly dead Google Code project called andro7z (http://code.google.com/p/andro7z/). This code contains a version of 7zip and a very, very basic JNI implementation. When you first grab the source, all it can do is print usage but it gives you a good starting point. I ended up studying and modifying it so I could return an array of strings containing the names of the files contained within the archive, as well as extract specific or all files from an archive. Since I was only working with 7z files, I didn't make it a very elegant implementation, but it works. Using the actual 7zip c/cpp sources means that out streams are handled properly and won't try to allocate outrageous dictionary sizes.

要编译andro7z你需要抓住了Android NDK,如果你不已经拥有了它。从那里,你将不得不编写自己的JNI方法,所以可以使用Java本机二进制文件进行交互。你会看到一些测试参数在7za.cpp的顶部,你就可以到这些注释和测试硬codeD提取。

To compile andro7z you'll need to grab the android NDK if you don't already have it. From there you're going to have to write your own JNI methods so you can interact with the native binaries using Java. You'll see some test arguments at the top of 7za.cpp, you'll be able to uncomment those and test a hard-coded extraction.

这篇关于J7zip在Android上 - 提取存档和清单内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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