小编Piy*_*gar的帖子

java.io.IOException:在解析头文件时检测到错误,在 Java 中解压 .tgz 文件

我正在使用 apache commons 来解压 .tgz 文件。我从压缩库中收到错误消息。我已经尝试过压缩 1.9 和 1.8.1 版本,但我仍然遇到相同的错误。

这仅发生在某些文件上,但问题是当我手动下载文件并验证它时,没有问题。

$ gunzip -c foo.tgz | tar t > /dev/null
$ 
Run Code Online (Sandbox Code Playgroud)

但是我看到这个堆栈跟踪来自公共库。

Severe:   java.io.IOException: Error detected parsing the header
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:257)    
...
Caused by: java.lang.IllegalArgumentException: Invalid byte 0 at offset 5 in '05412{NUL}11' len=8
at org.apache.commons.compress.archivers.tar.TarUtils.parseOctal(TarUtils.java:138)
Run Code Online (Sandbox Code Playgroud)

问题来自线路

entry = tarIn.getNextTarEntry();
Run Code Online (Sandbox Code Playgroud)

这是代码:

try {
        TarArchiveInputStream tarIn = new TarArchiveInputStream(
                new GZIPInputStream(
                        new BufferedInputStream(
                                new FileInputStream(
                                        tempDirPath + fileName))));

        TarArchiveEntry entry = tarIn.getNextTarEntry();

        while (entry != null) {
            File path = new …
Run Code Online (Sandbox Code Playgroud)

java apache tar apache-commons-compress

3
推荐指数
1
解决办法
4154
查看次数

标签 统计

apache ×1

apache-commons-compress ×1

java ×1

tar ×1