[Kaffe] a new patch for ZipOutputStream

Moses DeJong dejong at cs.umn.edu
Wed Feb 17 23:10:14 PST 1999


Hi all.

Here is my latest patch for ZipOutputStream. This patch also requires a
change to ZipConstants to add the defs for the offests for the "extended"
data header. This fixes a problem with the Jar program related to listing
of a jar with a compressed entry. This patch also has the ZipEntry.flag
patch that I send in yesterday. That patch had not been applied to the CVS
so doing a cvs diff had the side effect of adding it.

Mo DeJong
dejong at cs.umn.edu


Index: ZipConstants.java
===================================================================
RCS file: /home/cvspublic/kaffe/libraries/javalib/java/util/zip/ZipConstants.java,v
retrieving revision 1.4
diff -u -r1.4 ZipConstants.java
--- ZipConstants.java   1999/02/10 21:34:52     1.4
+++ ZipConstants.java   1999/02/18 07:52:31
@@ -65,8 +65,15 @@
 
   public final static long LOC_HEADSIG = 0x04034b50;
 
-  public final static long DATA_HEADSIG = 0x08074b50;
+  public final static int DATA_SIGNATURE = 0;
+  public final static int DATA_CRC = 4;
+  public final static int DATA_COMPRESSEDSIZE = 8;
+  public final static int DATA_UNCOMPRESSEDSIZE = 12;
+
   public final static int DATA_RECSZ = 16;
+
+  public final static long DATA_HEADSIG = 0x08074b50;
+
 
   public static final int DEFLATED = 8;
   public static final int STORED = 0;




Index: ZipOutputStream.java
===================================================================
RCS file: /home/cvspublic/kaffe/libraries/javalib/java/util/zip/ZipOutputStream.java,v
retrieving revision 1.4
diff -u -r1.4 ZipOutputStream.java
--- ZipOutputStream.java	1999/02/16 19:44:21	1.4
+++ ZipOutputStream.java	1999/02/18 08:09:25
@@ -27,6 +27,7 @@
 private byte[] lh = new byte[LOC_RECSZ];
 private byte[] ch = new byte[CEN_RECSZ];
 private byte[] ce = new byte[END_RECSZ];
+private byte[] da = new byte[DATA_RECSZ];
 private ZipEntry curr;
 private Vector dir;
 private OutputStream strm;
@@ -43,6 +44,9 @@
 private int len;
 
 Storer() {
+    total = 0;
+    off = 0;
+    len = 0;
 }
 
 public int deflate(byte[] b, int p, int l) {
@@ -128,6 +132,22 @@
 	curr.crc = crcval;
 	dout += curr.csize;
 
+
+	// I do not know exactly why, but adding an extended header to
+	// an uncompressed entry breaks things when extracting.
+
+	if (curr.method == DEFLATED) {
+	    // do method called putextended() from zipfile.c
+	    // IE : Write an extended local header (crc, csize, size)
+
+	    put32(da, DATA_SIGNATURE, (int)DATA_HEADSIG);
+	    put32(da, DATA_CRC, (int)curr.crc);
+	    put32(da, DATA_COMPRESSEDSIZE, (int) curr.csize);
+	    put32(da, DATA_UNCOMPRESSEDSIZE, (int) curr.size);
+
+	    strm.write(da);
+	}
+
 	curr = null;
 }
 
@@ -173,6 +193,7 @@
 	}
 
 	// Flag error if no entries were written.
+
 	if (count == 0) {
 	        throw new ZipException("ZIP file must have at least one entry");
 	}
@@ -195,9 +216,6 @@
 {
 	closeEntry();	// Close previous entry
 
-	put32(lh, LOC_SIGNATURE, (int)LOC_HEADSIG);
-	put16(lh, LOC_VERSIONEXTRACT, ZIPVER);
-	put16(lh, LOC_FLAGS, ze.flag);
 	if (ze.method == -1) {
 		ze.method = method;
 	}
@@ -210,6 +228,7 @@
 			throw new ZipException("crc not set in stored entry");
 		}
 	}
+	ze.flag = ze.method;
 
 	if (curr == null || curr.method != ze.method) {
 		if (ze.method == STORED) {
@@ -220,6 +239,9 @@
 		}
 	}
 
+	put32(lh, LOC_SIGNATURE, (int)LOC_HEADSIG);
+	put16(lh, LOC_VERSIONEXTRACT, ZIPVER);
+	put16(lh, LOC_FLAGS, ze.flag);
 	put16(lh, LOC_METHOD, ze.method);
 	put16(lh, LOC_TIME, 0);
 	put16(lh, LOC_DATE, 0);
@@ -233,10 +255,10 @@
 
 	strm.write(lh);
 	if (ze.name != null) {
-		strm.write(ze.name.getBytes());
+                strm.write(ze.name.getBytes());
 	}
 	if (ze.extra != null) {
-		strm.write(ze.extra);
+                strm.write(ze.extra);
 	}
 
 	ze.offset = dout;
@@ -277,14 +299,14 @@
 
 private void put16(byte[] zheader, int pos, int val) {
 	zheader[pos] = (byte)val;
-	zheader[pos+1] = (byte)(val >> 8);
+	zheader[pos+1] = (byte)(val >>> 8);
 }
 
 private void put32(byte[] zheader, int pos, int val) {
 	zheader[pos] = (byte)val;
-	zheader[pos+1] = (byte)(val >> 8);
-	zheader[pos+2] = (byte)(val >> 16);
-	zheader[pos+3] = (byte)(val >> 24);
+	zheader[pos+1] = (byte)(val >>> 8);
+	zheader[pos+2] = (byte)(val >>> 16);
+	zheader[pos+3] = (byte)(val >>> 24);
 }
 
 }



More information about the kaffe mailing list