The below code produces a zip file that can be opened in WinZip 8.1 when
compiled with Sun JRE 1.4.1_01.  When compiled with GCJ 3.4.0 the zip file is
produced but WinZip says it's corrupt.

Is this a bug in GCJ or am I misunderstanding how java.util.zip works in libgcj?

Thanks.

Usage:  Pass in two arguments to class.  First arg is name of archive and second
is the name of the file you want to add to the archive.

************************************************************************

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipMain {

        /**
         * 
         */
        public ZipMain() {
                super();
        }

        public static void main(String[] args) {
        
                String sArchive = args[0];
                String sFile = args[1];
                
                if (sArchive==null || sFile==null || 
                                sArchive.length()==0 || sFile.length()==0){
                        return;
                }
                
                File f = new File(sFile);
                
                if (!f.exists()){
                        return;
                }
                
                ZipOutputStream oArchive = null;
                File fArchive = new File(sArchive);

                try {
                        //open archive
                        oArchive = new ZipOutputStream(new 
FileOutputStream(fArchive));
                                oArchive.setLevel(Deflater.DEFAULT_COMPRESSION);
                        
                                //add file
                                
                        ZipEntry zipEntry = new ZipEntry(f.toString());
                        FileInputStream fin = new FileInputStream(f);
                        BufferedInputStream in = new BufferedInputStream(fin);
                        oArchive.putNextEntry(zipEntry);

                        byte[] buf = new byte[1024];
                        int len;
                        while ((len = in.read(buf)) >= 0) {
                                oArchive.write(buf, 0, len);
                        }
                        
                        //clean up
                        in.close();
                        oArchive.closeEntry();
                        oArchive.close();
                        
                } catch (Exception e){
                        e.printStackTrace();
                }
                
        }
}

-- 
           Summary: Creating archives with java.util.zip
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libgcj
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wayne dot gray at coynetextileservices dot com
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19109

Reply via email to