IOException:大小不匹配膨胀文件错误

时间:2015-08-19 13:50:14

标签: java android zip compression

在Android中,我有一个zip文件,我需要解压缩,但在解压缩时,我最终得到一个 IOException:大小不匹配的文件:6843932 v 0

我注意到在查看日志时,我看到一堆文件解压缩。

geocoord/Canada/Nad27Nad83/123w53n3d.dac, 85472 bytes.
Extracted 85472bytes.
geocoord/Canada/Nad27Nad83/bc27v1_1.dac, 48032 bytes.
Extracted 48032bytes.
geocoord/Canada/Nad27Nad83/readme_Nad27ToNad83.txt, 646 bytes.
Extracted 646bytes.
geocoord/Canada/Nad83Csrs/readme_Nad83ToCsrs.txt, 593 bytes.
Extracted 593bytes.
geocoord/Canada/readme_canada.txt, 534 bytes.
Extracted 534bytes.
geocoord/coordsys.dty, 0 bytes.

我的代码非常简单:

private final int BYTE_SIZE = 4096;
private void unzip( String src, String target )
  {
  try
        {
        zipFile = new ZipFile(src);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements())
            {
            ZipEntry entry = entries.nextElement();
            File entryDestination = new File(target, entry.getName());
            if (entry.isDirectory())
                entryDestination.mkdirs();
            else
                {
                entryDestination.getParentFile().mkdirs();
                InputStream in = zipFile.getInputStream(entry);
                OutputStream out = new FileOutputStream(entryDestination);
                Log.i("log_me", entry.getName() + ", " + entry.getSize() + " bytes.");
                int len = 0;
                long count = 0;
                byte[] arr = new byte[BYTE_SIZE];
                while ((len = in.read(arr)) > 0)
                    {
                    out.write(arr, 0, len);
                    count += len;
                    }
                out.flush();
                out.close();
                in.close();
                Log.i("log_me", "Extracted " + count + "bytes.");
                }
            }
        } 
    catch (Exception e)
        {
        e.printStackTrace();
        } 
    finally
        {
        try
            {                                                
            if (zipFile != null)
                zipFile.close();
            } 
        catch (Exception e)
            {
            e.printStackTrace();
            }
        }
    }
  }

所以你可以看到它看起来正确地做到了。

有没有人看到异常?我刚解压缩文件,它显示文件:geocoord / coordsy.dty具有以下统计信息。

Name          Size  Packed   Type        Modified     CRC32
 coordsys.dty  0     521,565  DTY File    7/9/2015     441587F9

压缩会发生什么事吗?好像它可能没有正确压缩这些文件。 (另一位同事写了拉链)

我正在查看他的bash脚本以获得他的拉链,他写了这样的东西:

ZipArgs= -r -9 
@$(SrcRoot)bsitools\winx86\zip.exe $(ZipArgs) $(ZipTargetFile) $(ZipSourcePath) 

当查看zip.exe文件时,显示如下命令:

Copyright (C) 1990-1993 Mark Adler, Richard B. Wales, Jean-loup Gailly
and Kai Uwe Rommel. Type 'zip -L' for the software License.

Zip 2.0.1 (Sept 18th 1993). Usage:
zip [-options] [-b path] [-t mmddyy] [-n suffixes] [zipfile list] [-xi list]
The default action is to add or replace zipfile entries from list, which
can include the special name - to compress standard input.
If zipfile and list are omitted, zip compresses stdin to stdout.
-f   freshen: only changed files  -u   update: only changed or new files
-d   delete entries in zipfile    -m   move into zipfile (delete files)
-k   simulate PKZIP made zipfile  -g   allow growing existing zipfile
-r   recurse into directories     -j   junk (don't record) directory names
-0   store only                   -l   convert LF to CR LF (-ll CR LF to LF)
-1   compress faster              -9   compress better
-q   quiet operation              -v   verbose operation
-c   add one-line comments        -z   add zipfile comment
-b   use "path" for temp file     -t   only do files after "mmddyy"
-@   read names from stdin        -o   make zipfile as old as latest entry
-x   exclude the following names  -i   include only the following names
-F   fix zipfile (-FF try harder) -D   do not add directory entries
-T   test zipfile integrity       -L   show software license
-$   include volume label         -S   include system and hidden files
-h   show this help               -n   don't compress these suffixes

我认为-r -9对他的拉链来说还不够。似乎该文件没有压缩1级深度的文件,但在后续目录中正确地执行所有其他文件。

编辑:   我注意到它打印出来了:

test of %My_Path%geocoord.zip FAILED

zip error: Zip file invalid or insufficient memory (original files unmodified)

更新

正在压缩的文件是SYMLINK文件和文件夹。它递归地遍历这些子文件夹,但文件本身只是复制PTR而不是实际数据。

1 个答案:

答案 0 :(得分:0)

zip文件工具正在压缩符号链接,但符号链接显示大小因为它们很好,只是指针。因此大小已经关闭。