问题标签 [apache-commons-compress]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
773 浏览

java - 使用 ColdFusion 解压缩 64 位 zip 文件

我以前用java.util.zip.ZipFileColdFusion 解压缩大文件。但是,我现在收到此错误:“无效的 CEN 标头(错误签名)”。

我发现一个帖子表明这与 zip 64 位格式有关,我可以用java.util.zip.ZipInputStream它来处理它。但是,我无法克服这个错误:“您试图取消引用类型类 [B 作为具有成员的结构的标量变量。” 这是由这一行引起的:

任何帮助是极大的赞赏!

这是我的代码

来源:

0 投票
1 回答
1075 浏览

gzip - How do i create a "valid" unix TAR Archive in Windows with Java (apache compress)?

I'm trying to create a 'valid' tar.gz archive by using the apache commons compress librarys. The created archive will be read by an embedded device and has to be in the same format with the same file permissions i think.

If i'm using Linux to create my file, everything works fine, but if i'm using Windows. The file is rejected.

As you can see, the archive only contains to special files with unix permissions. these are correctly set and if i use a "working" tar file and run it through gzip, the created tar.gz also works fine.

The only difference i figured out is, that the non-working tar file is slightly larger (61 instead of 56 kb) and 7zip shows under "Host OS" FAT instead of Unix.

Any ideas, how i can create a "real" tar archive from Windows?

Thanks in advance!

My current sourcecode is:

I've done some research and noticed a difference between the TAR headers. Can anybody tell, what i am doing wrong?

0 投票
1 回答
363 浏览

java - 这个输入流被关闭了吗?

使用读取嵌入式存档文件时遇到一些非常奇怪的错误org.apache.commons.compress,我怀疑是我的经验不足困扰着我。

运行我的代码时,我收到各种截断的 zip 文件错误(以及其他截断的文件错误)。我怀疑这是我使用的ArchiveInputStream

当我这样做时,这archiveEntry = ais.getNextEntry()是否有效地关闭了我的ais,并且有什么方法可以使用 commons compress 读取嵌入式存档文件的字节?

0 投票
2 回答
7770 浏览

java - 使用 Apache Commons Compress 解压缩 tar 文件

我正在使用 Apache Commons Compress 创建 tar 存档并解压缩它们。我的问题始于这种方法:

每次我运行代码时,compressedFile 变量为空,但 while 循环正在遍历我的测试 tar 中的所有条目。

你能帮我理解我做错了什么吗?

0 投票
1 回答
5207 浏览

java - 将字节数组写入 ZipArchiveOutputStream

我需要创建一个 zip 文件并受到以下条件的限制:

  • 这些条目以 byte[](或 ByteArrayOutputStream)的形式出现,而不是 File。
  • 条目的文件名可以是非 ascii/UTF-8。
  • JDK 1.6 或更早版本

由于 java.util.zip 仅支持 JDK 1.7 及更高版本的 UTF-8 文件名,因此使用 commons-compress ZipArchiveOutputStream 似乎更好。但是如何基于字节数组或 ByteArrayOutputStream 而不是 File 创建 ZipEntryArchive?

谢谢!

0 投票
2 回答
2339 浏览

java - 如何加密 java 7z 存档?

我正在使用 Apache Commons Compress 来压缩文件。如何将密码添加到存档中?

0 投票
1 回答
782 浏览

spring-mvc - java.util.zip.ZipEntry 和 apache 压缩 ZipEntry 损坏了一些图像文件

我一直在使用 Spring 的多部分上传器控制器来上传和存储压缩文件中的条目,但我发现偶尔的 PNG 文件已损坏,而不是以字节 [] 中的“PNG ...”之类的开头,而是开始用“fþ»ÀÃgÞÉ”或类似的词。这似乎发生在每次运行的相同文件上。我使用 java.util.ZipEntry 尝试了所有这些,然后我尝试了 Apache Compress,发现 Apache 将损坏的不同文件压缩到 Java 7 实用程序,但在随后的运行中总是相同的文件。

代码(首先是 java.util.zip.ZipEntry):

现在对于 org.apache.commons.compress.archivers.zip.ZipFile 也是一样的:

两个被调用的方法是:

和:

当然,第二个不太可能是问题的一部分。

我用谷歌搜索了一下,似乎发现了与此类似的问题,但它一直是一些外部问题。有谁知道为什么会这样?

我重新编辑了一些图像,发现如果我将图像更改为黑白,或者更改整个图像的色调,问题就会消失,但如果我添加边框或更改单一颜色,问题仍然存在。看起来某些文件中的特定字节排列会在 Java 自己的和 Apache 的压缩文件阅读器使用的任何底层 API 中引起错误,但这只是猜测。

编辑:其他用法表明损坏发生在大小超过 10K 的 gif 中,所以这可能与错误有关?我曾尝试在调用 ReadInputStream() 时将缓冲区的大小任意加倍,但除了在特别大的图像中溢出 MySQL 中的 blob 大小(49K 变成 98K,这太​​大了)之外,它什么也没做。

0 投票
1 回答
1474 浏览

java - ServletOutputStream 创建包含多个 zip 的单个 zip 失败

我正在使用 commons compress 压缩多个文件并将其从 Servlet 发送到客户端。这些文件可以是任何类型的文件(文本、视频、音频、档案、图像等)的组合。我使用 IOUtils.copy(is, os) 获取文件的 inputStream 并写入 ServletOutputStream。该代码通常适用于任何文档组合,但是当请求下载包含超过 1 个 zip 的文件时,我得到java.io.IOException: Closed 结果,即使 zip 的大小是单个文件大小的总和,创建的 zip 文件也已损坏(我我没有使用压缩)。

我尝试在本地创建 zip 并使用FileOutputStream而不是response.getOutputStream()在构造函数中ZipArchiveOutputStream,它成功了。因此,看起来问题存在于ServletOutputStream.

任何人都可以提出任何解决方法。

这是我的代码:

`

这是异常跟踪:`

第 110 行是zipOutputStream.closeArchiveEntry(); //**Starts to fail here after 1st zip is added**

提前致谢。

0 投票
1 回答
13461 浏览

java - Read tar.gz in Java with Commons-compression

Ok so I want to read the contents of a tar.gz file (or a xy) but that's the same thing. What I am doing is more or less this:

But I get null when I call the getFile method of TarArchiveEntry.
I am using Apache commons compress 1.8.1

0 投票
1 回答
3336 浏览

java - Gradle 不包含可选依赖

我有一个项目,该项目将apache-compress库作为编译时依赖项。这个库似乎使用 Maven,并且有一个 POM 文件,其依赖项设置为“可选”。以下是 POM 文件的相关部分:

Gradle 似乎没有将此库包含在我的项目中,我猜这是因为“可选”属性。有什么方法可以告诉 Gradle 在不明确包含 xz 库的情况下包含此依赖项吗?

这是我的 Gradle 依赖声明:compile group: 'org.apache.commons', name:'commons-compress', version:'1.8.1'