apparent issues with java.util.zip

30 views
Skip to first unread message

John Bankert

unread,
Aug 23, 2016, 11:30:15 AM8/23/16
to Avian
All,

I'm trying to create zip files using java.util.zip in Avian, and am having two problems.

The first is that the written to disk by the zip.output stream is the same size as when written to disk using file output stream.

The second is when calling zipOutputStream.closeEntry(); I receive the following error from the program:

java.util.zip.Deflater.b (native)
java.util.zip.e.d (native)
java.util.zip e.c (native)

I would also note that I've tried using java.util.Deflater and Inflater on the byte array, and they appear to work correctly. Here is the code I'm using:

    private void saveAsCompressedBitmap(byte[] bytes, String fn)
    {
        String zFn = fn + ".zip";
        fn += ".bmp";
        // Avian doesn't support try-with-resources and FileOutputStream, ZipOutputStream
        FileOutputStream fos = null;
        ZipOutputStream zos = null;
        try //(FileOutputStream fos = new FileOutputStream(FPATH + zFn);
            //ZipOutputStream zos = new ZipOutputStream(fos);)
        {
            fos = new FileOutputStream(FPATH + zFn);
            zos = new ZipOutputStream(fos);
            ZipEntry ze = new ZipEntry(fn);
            zos.putNextEntry(ze);
            zos.write(bytes);
        }
        catch(IOException ie)
        {
            System.out.println("saveAsCompressedBitmap failed!");
            for (StackTraceElement ste : ie.getStackTrace())
                System.err.println(ste.toString());
        } 
        finally
        {
            try
            {
                if (zos != null)
                {
                    zos.closeEntry(); // This is where the exception is being generated.
                    zos.close();
                }
                if (fos != null) fos.close();
            }
            catch(Exception e)
            {
                // TODO Auto-generated catch block
                for (StackTraceElement ste : e.getStackTrace())
                    System.err.println(ste.toString());
            }
        }
    }

Joel Dice .

unread,
Aug 24, 2016, 12:50:31 AM8/24/16
to Avian
Hi John,

Thanks for reporting this. I was able to reproduce it, and this fixed
the exception for me: https://github.com/ReadyTalk/avian/pull/496

However, the resulting zip file still appears to be corrupt, so there
are apparently other issues with ZipOutputStream. I don't have time
now to debug it further, but I'll take another look when I get a
chance.
> --
> You received this message because you are subscribed to the Google Groups
> "Avian" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to avian+un...@googlegroups.com.
> To post to this group, send email to av...@googlegroups.com.
> Visit this group at https://groups.google.com/group/avian.
> For more options, visit https://groups.google.com/d/optout.

Joel Dice .

unread,
Sep 3, 2016, 4:28:59 PM9/3/16
to Avian
Sorry for the delay, but I finally had a chance to come back to this.
It turns out the zip file corruption I was seeing was due to my
failure to call ZipOutputStream.closeEntry in the test I was using.
Once I added that, everything worked fine.

I've updated our test suite to make sure we test all three overloads
of ZipOutputStream.write: https://github.com/ReadyTalk/avian/pull/497

Please let me know if you still have any problems.
Reply all
Reply to author
Forward
0 new messages