SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Problem reading deflated files from Java

Last post 09-08-2008 6:16 PM by Massimo Gentilini. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 09-02-2008 10:44 AM

    Problem reading deflated files from Java

    If I create a #Zip file from .Net I get errors when reading it from Java using the Java.Utils.Zip library.

    Examining the file created via AEX tool it seems there is an error of mismatch between compressed and uncompressed size in the local file entry, while the central file header is correct:

    <<Local file entry
     Version 4.5
     Flags   0000   Normal compression
     Method  Deflated
     Date    9/2/2008 10:33:36 AM
     Name    'Connectors.config'
     Crc     68741CD4   Compressed size 128  Uncompressed size 140 
     Header mismatch - compressed size different
     Header mismatch - uncompressed sizes are different

    <<Central file header
     Version                 made by 4.5   to extract 4.5
     OS                      MSDOS + OS/2,NT (FAT+VFAT+NTFS)
     Flags                   0000   Normal compression
     Method                  Deflated
     Name length             17
     Comment length          0
     Internal attributes     00
     External attributes     0000 MSDOS ------
     Name                    'Connectors.config'
     Disk number start       0
     Relative header offset  0
     Crc    68741CD4   Compressed size 128  Uncompressed size 140 

    <<End of Central file header
     Disk number             0
     Start dir disk number   0
     Entries this disk       1
     Total entries           1
     Central directory size  83
     Offset                  195

    EOF
    Done

    I've tried various options assigning compressed and uncompressed size to the zipentry but it fails every time, only way I've found to make it work is to store the file (so no compression happens) and assigning Size and CompressedSize to be the same as file length, but this makes compressing files useless:

    FileInfo fileInfo = new FileInfo(FileFullPathName);using (FileStream fs = File.OpenRead(FileFullPathName))

    {

    byte[ buffer = new byte[fs.Length];

    fs.Read(buffer, 0, buffer.Length);

     

    ZipEntry entry = new ZipEntry(fileInfo.Name);entry.CompressionMethod = CompressionMethod.Stored;

    entry.CompressedSize = fs.Length;

    entry.Size = fs.Length;

    entry.DateTime =
    DateTime.Now;

    fs.Close();

     

    Zipper.PutNextEntry(entry);

    Zipper.Write(buffer, 0, buffer.Length);

    Zipper.Flush();

    Zipper.CloseEntry();

    }

     This is instead the code I'm using that fails, if I set any kind of property to Size or CompressedSize the AEX tool fails also on the Central File Header part :

    FileInfo fileInfo = new FileInfo(FileFullPathName);using (FileStream fs = File.OpenRead(FileFullPathName))

    {

    byte[ buffer = new byte[fs.Length];

    fs.Read(buffer, 0, buffer.Length);

    ZipEntry entry = new ZipEntry(fileInfo.Name);

    entry.DateTime = DateTime.Now;

    fs.Close();

    Crc32 crc = new Crc32();

    crc.Reset();

    crc.Update(buffer);

    entry.Crc = crc.Value;

    Zipper.PutNextEntry(entry);

    Zipper.Write(buffer, 0, buffer.Length);

    Zipper.Flush();

    Zipper.CloseEntry();

    }

     

    Suggestions???

    Regards

    Massimo

     

     

  • 09-02-2008 9:48 PM In reply to

    Re: Problem reading deflated files from Java

    Hi,

    Try not setting the sizes at all.  Its ok to set the uncompressed size and this works fine for me and helps with Zip64 issues. (What version of the library are you using?)

    Cheers, -jr-
  • 09-04-2008 1:11 PM In reply to

    Re: Problem reading deflated files from Java

    I'm using the latest version (0.85.5.452).

    Current code do not set any size, because if I set any of them also the TestArchive function of #ZipLib fails when I test the created archive in the code following.

    I've made some test trying to force the usage of Zip64, but the result remained the same, AEX gives an error and the file cannot be decompressed from the Java library.

     Regards

    Massimo

     

  • 09-04-2008 9:44 PM In reply to

    Re: Problem reading deflated files from Java

     Hi,

    You arent tracking the number of bytes read from the file but rather are adding the entire buffer which may the problem.

    hth, -jr-

  • 09-08-2008 4:59 PM In reply to

    Re: Problem reading deflated files from Java

    Could you post a quick code sample about how to track this info?

     Regards

    Massimo

  • 09-08-2008 6:16 PM In reply to

    Re: Problem reading deflated files from Java

    I've tried to place an Assert on the fs.Length and the number of bytes read from the buffer but, for all cases I have, the values are the same.

     My idea it's a problem in the library code, specifically in the Zip header write (that has also a TODO Refactor comment in it) that always assign -1 to the compressed size of the entry.

    Regards

    Massimo

Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.