public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/19109] New: Creating archives with java.util.zip
@ 2004-12-21 14:41 wayne dot gray at coynetextileservices dot com
  2004-12-21 14:48 ` [Bug libgcj/19109] " belyshev at lubercy dot com
  2004-12-21 15:48 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 5+ messages in thread
From: wayne dot gray at coynetextileservices dot com @ 2004-12-21 14:41 UTC (permalink / raw)
  To: java-prs

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


^ permalink raw reply	[flat|nested] 5+ messages in thread
[parent not found: <bug-19109-8172@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2016-01-12 16:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-21 14:41 [Bug libgcj/19109] New: Creating archives with java.util.zip wayne dot gray at coynetextileservices dot com
2004-12-21 14:48 ` [Bug libgcj/19109] " belyshev at lubercy dot com
2004-12-21 15:48 ` pinskia at gcc dot gnu dot org
     [not found] <bug-19109-8172@http.gcc.gnu.org/bugzilla/>
2015-10-20 16:30 ` hjl at gcc dot gnu.org
2016-01-12 16:27 ` hjl at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).