Android 上的 J7zip - 从档案中提取并列出内容 [英] J7zip on Android - Extracting From an Archive and Listing Contents

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

问题描述

我之前的问题因为没有建设性而被关闭.我在那里编辑了它,但没有看到它已关闭):

我正在编写一个涉及提取 7z 档案的应用程序.似乎没有任何本机支持,所以我冒险寻找可以集成到我的项目中的第三方库或源代码.

我一直在尝试实施 J7zip,但没有成功.>

列出档案的内容不返回任何文件:

12-24 13:36:44.216: I/System.out(18473): J7zip 4.43 ALPHA 2(2 个 CPU)12-24 13:36:44.232:I/System.out(18473):日期时间属性大小压缩名称12-24 13:36:44.232: I/System.out(18473): -------------- ----- ------------ -———————————————12-24 13:36:44.240: I/System.out(18473): -------------- ----- ------------ -———————————————

但是,在 windows 上列出内容(使用 7z.exe)返回以下内容

7-Zip 9.22 beta 版权所有 (c) 1999-2011 Igor Pavlov 2011-04-18上市档案:archive.7z——路径 = 存档.7z类型 = 7z方法 = LZMA固体 = -块 = 1物理尺寸 = 183119标题大小 = 122日期时间属性大小压缩名称-------------------- ----- ------------ ------------ -----------------..... 524288 182997 内容.txt-------------------- ----- ------------ ------------ -----------------524288 182997 1 个文件,0 个文件夹

提取失败,我有那个这里的日志,因为它有点长.

这里似乎存在 io 问题,但我怀疑还有其他原因,因为列出此存档没有返回任何文件.

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

解决方案

这里有几个可能的解决方案.

我首先尝试交叉编译 7zip jbinding 项目.我在我的机器上安装了 armeabi c 和 c++ 编译器并尝试构建项目.不幸的是,我无法构建可用于 Android 项目的二进制文件.我在论坛帖子中提到了导致尝试加载编译的 jbinding 二进制文件时出现问题的库.

我的下一个领导是实现 p7z 的 Java 端口,J7zip (http://sourceforge.net/projects/p7zip/files/J7Zip/).实现这一点还不错,只是我必须修改代码,j7z 库将尝试写入 SD 卡的根目录(无根访问权限).此端口在大多数情况下运行良好,但在提取较大的存档或包含许多类似文件的存档时会导致内存不足错误.问题是库试图为字典分配太多内存(它会分配所有提取内容的大小,即使您只想提取一个文件).所以这个库在我的情况下不起作用,我认为它不会支持你正在使用的压缩.

最后,我到达了这个看似已死的谷歌代码项目,名为 andro7z (http://code.google.com/p/andro7z/).这段代码包含一个 7zip 版本和一个非常非常基本的 JNI 实现.当您第一次获取源时,它所能做的就是打印用法,但它为您提供了一个很好的起点.我最终研究并修改了它,以便我可以返回包含存档中包含的文件名称的字符串数组,以及从存档中提取特定或所有文件.因为我只处理 7z 文件,所以我没有让它成为一个非常优雅的实现,但它有效.使用实际的 7zip c/cpp 源意味着可以正确处理输出流,并且不会尝试分配过大的字典大小.

要编译 andro7z,如果您还没有 Android NDK,则需要获取它.从那里您将不得不编写自己的 JNI 方法,以便您可以使用 Java 与本机二进制文件进行交互.您将在 7za.cpp 的顶部看到一些测试参数,您将能够取消对它们的注释并测试硬编码提取.

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

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.

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): -------------- ----- ------------ ------------  ------------

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

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

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

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

解决方案

There are a few possible solutions here.

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.

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.

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.

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.

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

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