[kaffe] CVS kaffe (robilad): updated zlib-zip

Kaffe CVS cvs-commits at kaffe.org
Thu Jan 31 12:51:15 PST 2008


PatchSet 7723 
Date: 2008/01/31 20:49:45
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
updated zlib-zip

2008-01-31  Dalibor Topic  <robilad at kaffe.org>

        * TODO: Updated.

        * libraries/javalib/zlib-zip/java/util/zip/ZipEntry.java,
        libraries/javalib/zlib-zip/java/util/zip/ZipInputStream.java,
        libraries/javalib/zlib-zip/java/util/zip/ZipOutputStream.java:
        Removed.

        * kaffe/kaffevm/debug.c (kaffe_dprintf): Changed prototype of
        max to size_t.

        * libraries/clib/zip/ZipFile.c: Include native.h amd zzip/zzip.h.
        (makeZipEntry, java_util_zip_ZipFile_openZipFile0,
        java_util_zip_ZipFile_closeZipFile0, java_util_zip_ZipFile_getZipFileSize0,
        java_util_zip_ZipFile_getZipEntry0, java_util_zip_ZipFile_getZipData0,
        java_util_zip_ZipFile_getZipEntries0) Rewritten to use zziplib.
        (getZipEntry) New helper function.

        * libraries/javalib/zlib-zip/Makefile.am (dist_zlib_JAVA):
        Removed /java/util/zip/ZipEntry.java, java/util/zip/ZipInputStream.java
        and java/util/zip/ZipOutputStream.java.

        * libraries/javalib/zlib-zip/java/util/zip/ZipFile.java (getZipEntry):
        New private helper method. (getEntry, getInputStream) Use getZipEntry
        to avoid infinte recursion with overridden getEntry.

Members: 
	ChangeLog:1.5224->1.5225 
	TODO:1.47->1.48 
	kaffe/kaffevm/debug.c:1.67->1.68 
	libraries/clib/zip/ZipFile.c:1.1->1.2 
	libraries/javalib/zlib-zip/Makefile.am:1.7->1.8 
	libraries/javalib/zlib-zip/Makefile.in:1.27->1.28 
	libraries/javalib/zlib-zip/java/util/zip/ZipEntry.java:1.1->1.2(DEAD) 
	libraries/javalib/zlib-zip/java/util/zip/ZipFile.java:1.1->1.2 
	libraries/javalib/zlib-zip/java/util/zip/ZipInputStream.java:1.1->1.2(DEAD) 
	libraries/javalib/zlib-zip/java/util/zip/ZipOutputStream.java:1.1->1.2(DEAD) 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.5224 kaffe/ChangeLog:1.5225
--- kaffe/ChangeLog:1.5224	Mon Jan 28 00:59:32 2008
+++ kaffe/ChangeLog	Thu Jan 31 20:49:45 2008
@@ -1,3 +1,30 @@
+2008-01-31  Dalibor Topic  <robilad at kaffe.org>
+
+	* TODO: Updated.
+
+	* libraries/javalib/zlib-zip/java/util/zip/ZipEntry.java,
+	libraries/javalib/zlib-zip/java/util/zip/ZipInputStream.java,
+	libraries/javalib/zlib-zip/java/util/zip/ZipOutputStream.java:
+	Removed.
+
+	* kaffe/kaffevm/debug.c (kaffe_dprintf): Changed prototype of
+	max to size_t.
+
+	* libraries/clib/zip/ZipFile.c: Include native.h amd zzip/zzip.h.
+	(makeZipEntry, java_util_zip_ZipFile_openZipFile0, 
+	java_util_zip_ZipFile_closeZipFile0, java_util_zip_ZipFile_getZipFileSize0,
+	java_util_zip_ZipFile_getZipEntry0, java_util_zip_ZipFile_getZipData0, 
+	java_util_zip_ZipFile_getZipEntries0) Rewritten to use zziplib.
+	(getZipEntry) New helper function.
+
+	* libraries/javalib/zlib-zip/Makefile.am (dist_zlib_JAVA):
+	Removed /java/util/zip/ZipEntry.java, java/util/zip/ZipInputStream.java
+	and java/util/zip/ZipOutputStream.java.
+
+	* libraries/javalib/zlib-zip/java/util/zip/ZipFile.java (getZipEntry):
+	New private helper method. (getEntry, getInputStream) Use getZipEntry
+	to avoid infinte recursion with overridden getEntry.
+	
 2008-01-27  Dalibor Topic  <robilad at kaffe.org>
 
 	* config/arm/netbsd1/md.c,
Index: kaffe/TODO
diff -u kaffe/TODO:1.47 kaffe/TODO:1.48
--- kaffe/TODO:1.47	Tue Jan 22 14:42:16 2008
+++ kaffe/TODO	Thu Jan 31 20:49:45 2008
@@ -13,6 +13,7 @@
    * libjit could use a vmgenned interpreter, too.
 
 * Cleanup
+ * Don't use __USE_GNU use _GNU_SOURCE instead
  * cleanup JNI library loading to use libltdl exclusively.
  * Remove unused instructions from jits (nop, unimplemented)
 
Index: kaffe/kaffe/kaffevm/debug.c
diff -u kaffe/kaffe/kaffevm/debug.c:1.67 kaffe/kaffe/kaffevm/debug.c:1.68
--- kaffe/kaffe/kaffevm/debug.c:1.67	Tue Nov  7 00:59:10 2006
+++ kaffe/kaffe/kaffevm/debug.c	Thu Jan 31 20:49:47 2008
@@ -429,7 +429,7 @@
 {
 
 	int n;
-	int max;
+	size_t max;
 	va_list args;
 	ssize_t w = 0;
 	int rc;
@@ -441,7 +441,7 @@
 #ifdef HAVE_VSNPRINTF
 	max = bufferSz - bufferBegin - 1;
 	assert(max > 0);
-	n = vsnprintf(debugBuffer + bufferBegin, (unsigned int)max, fmt, args);
+	n = vsnprintf(debugBuffer + bufferBegin, max, fmt, args);
 
 	/* The return value is bytes *needed* not bytes *used* */
 	if (n > max)
Index: kaffe/libraries/clib/zip/ZipFile.c
diff -u kaffe/libraries/clib/zip/ZipFile.c:1.1 kaffe/libraries/clib/zip/ZipFile.c:1.2
--- kaffe/libraries/clib/zip/ZipFile.c:1.1	Sun Jul 23 15:48:26 2006
+++ kaffe/libraries/clib/zip/ZipFile.c	Thu Jan 31 20:49:47 2008
@@ -18,17 +18,38 @@
 #include "gtypes.h"
 #include "itypes.h"
 #include "jar.h"
+#include "native.h"
+
+#include <zzip/zzip.h>
 
 #include "java_util_zip_ZipEntry.h"
 #include "java_util_zip_ZipFile.h"
 #include "java_util_Vector.h"
 
-static Hjava_util_zip_ZipEntry* makeZipEntry(jarEntry*);
+static
+Hjava_util_zip_ZipEntry*
+makeZipEntry(ZZIP_FILE * entry, Hjava_lang_String* zname)
+{
+	Hjava_util_zip_ZipEntry* zentry;
+	ZZIP_STAT stat;
+	zzip_fstat(entry, &stat);
+
+	zentry = (Hjava_util_zip_ZipEntry*)
+	    execute_java_constructor("java.util.zip.ZipEntry", NULL, NULL, 
+				     "(Ljava/lang/String;)V", zname);
+	unhand(zentry)->size = stat.st_size;
+	unhand(zentry)->known |= java_util_zip_ZipEntry_KNOWN_SIZE;
+	unhand(zentry)->method = stat.d_compr;
+	unhand(zentry)->compressedSize = stat.d_csize;
+	unhand(zentry)->dostime = -1;
+	
+	return (zentry);
+}
 
 struct Horg_kaffe_util_Ptr*
 java_util_zip_ZipFile_openZipFile0(Hjava_lang_String* fname)
 {
-	jarFile* zip;
+	ZZIP_DIR* zip;
 	char* str;
 
 	str = checkPtr(stringJava2C(fname));
@@ -40,36 +61,52 @@
 void
 java_util_zip_ZipFile_closeZipFile0(struct Horg_kaffe_util_Ptr* zip)
 {
-	closeJarFile((jarFile*)zip);
+	closeJarFile((ZZIP_DIR*)zip);
 }
 
 jint
 java_util_zip_ZipFile_getZipFileSize0(struct Horg_kaffe_util_Ptr* zip)
 {
-	return ((jarFile*)zip)->count;
+  jint size = 0;
+
+  zzip_rewinddir((ZZIP_DIR *) zip);
+
+  while(zzip_readdir((ZZIP_DIR *) zip) != NULL)
+    ++size;
+
+  return size;
 }
 
-struct Hjava_util_zip_ZipEntry*
-java_util_zip_ZipFile_getZipEntry0(struct Horg_kaffe_util_Ptr* zip, Hjava_lang_String* zname)
+static
+ZZIP_FILE* getZipEntry(struct Horg_kaffe_util_Ptr* zip, Hjava_lang_String* zname)
 {
-	jarEntry* entry;
+	ZZIP_FILE* entry;
 	char* str;
-	Hjava_util_zip_ZipEntry* zentry;
 
 	str = checkPtr(stringJava2C(zname));
-	entry = lookupJarFile((jarFile*)zip, str);
+	entry = lookupJarFile((ZZIP_DIR*)zip, str);
 	gc_free(str);
-	if (entry == NULL) {
-		return (NULL);
-	}
-	zentry = makeZipEntry(entry);
-	return (zentry);
+
+	return entry;
+}
+
+struct Hjava_util_zip_ZipEntry*
+java_util_zip_ZipFile_getZipEntry0(struct Horg_kaffe_util_Ptr* zip, Hjava_lang_String* zname)
+{
+  ZZIP_FILE* entry;
+  Hjava_util_zip_ZipEntry* zentry = NULL;
+
+  entry = getZipEntry(zip, zname);
+
+  if (entry != NULL)
+    zentry = makeZipEntry(entry, zname);
+  
+  return (zentry);
 }
 
 HArrayOfByte*
 java_util_zip_ZipFile_getZipData0(struct Horg_kaffe_util_Ptr* zip, struct Hjava_util_zip_ZipEntry* zentry)
 {
-	jarEntry entry;
 	HArrayOfByte* array;
 	uint8* buf = NULL;
 	jlong size;
@@ -81,16 +118,13 @@
         }
 	if( size > 0 )
 	{
-		entry.fileName = NULL;
-		entry.uncompressedSize = size;
-		entry.compressionMethod = unhand(zentry)->method;
-		entry.compressedSize = unhand(zentry)->csize;
-		entry.localHeaderOffset = unhand(zentry)->offset;
-		
-		buf = getDataJarFile((jarFile*)zip, &entry);
-		if (buf == 0) {
-			return (NULL);
-		}
+	  ZZIP_FILE *entry = getZipEntry( zip, unhand(zentry)->name);
+	  if (entry != NULL)
+	    buf = getDataJarFile(entry);
+
+	  if (buf == 0) {
+	    return (NULL);
+	  }
 	}
 	array = (HArrayOfByte*)AllocArray((jsize)size, TYPE_Byte);
 	if( buf )
@@ -105,50 +139,31 @@
 java_util_zip_ZipFile_getZipEntries0(struct Horg_kaffe_util_Ptr* zip)
 {
 	Hjava_util_Vector* vec;
-	jarFile* zfile;
-	jarEntry* entry;
+	ZZIP_DIR* zfile;
+	ZZIP_FILE* entry;
+	ZZIP_DIRENT * zip_entry = NULL; 
 	HObject** elems;
 	int i = 0;
-	unsigned int j;
-
-	zfile = (jarFile*)zip;
-	vec = (Hjava_util_Vector*)execute_java_constructor("java.util.Vector",
-	    NULL, NULL, "(I)V", zfile->count);
+	jint num_entries = java_util_zip_ZipFile_getZipFileSize0(zip);
+	zfile = (ZZIP_DIR*)zip;
+	
+	vec = (Hjava_util_Vector*)
+	  execute_java_constructor("java.util.Vector",
+				   NULL, NULL, "(I)V", 
+				   num_entries);
 	elems = unhand_array(unhand(vec)->elementData)->body;
-	for (j = 0; j < zfile->tableSize; j++) {
-		entry = zfile->table[j];
-		while( entry )
-		{
-			elems[i] = (HObject*)makeZipEntry(entry);
-			i++;
-			entry = entry->next;
-		}
-	}
-	unhand(vec)->elementCount = zfile->count;
 
-	return (vec);
-}
+	zzip_rewinddir(zfile);
+	do {
+	  zip_entry = zzip_readdir(zfile);
+	  if (NULL != zip_entry) {
+	    entry = lookupJarFile(zfile, zip_entry->d_name);
+	    elems[i] = (HObject*)makeZipEntry(entry, stringC2Java(zip_entry->d_name));
+	    i++;
+	  }
+	}while (zip_entry != NULL);
 
-static
-Hjava_util_zip_ZipEntry*
-makeZipEntry(jarEntry* entry)
-{
-	Hjava_util_zip_ZipEntry* zentry;
+	unhand(vec)->elementCount = num_entries;
 
-	zentry = (Hjava_util_zip_ZipEntry*)
-	    execute_java_constructor("java.util.zip.ZipEntry", NULL, NULL, "()V");
-	unhand(zentry)->name =
-	    checkPtr(stringC2Java(entry->fileName));
-	unhand(zentry)->crc = 0;
-	unhand(zentry)->size = entry->uncompressedSize;
-	unhand(zentry)->method = entry->compressionMethod;
-	unhand(zentry)->extra = NULL;
-	unhand(zentry)->comment = NULL;
-	unhand(zentry)->flag = 0;
-	unhand(zentry)->version = 0;
-	unhand(zentry)->csize = entry->compressedSize;
-	unhand(zentry)->offset = entry->localHeaderOffset;
-	unhand(zentry)->dosTime = entry->dosTime;
-
-	return (zentry);
+	return (vec);
 }
Index: kaffe/libraries/javalib/zlib-zip/Makefile.am
diff -u kaffe/libraries/javalib/zlib-zip/Makefile.am:1.7 kaffe/libraries/javalib/zlib-zip/Makefile.am:1.8
--- kaffe/libraries/javalib/zlib-zip/Makefile.am:1.7	Sun Dec  9 20:47:21 2007
+++ kaffe/libraries/javalib/zlib-zip/Makefile.am	Thu Jan 31 20:49:48 2008
@@ -27,10 +27,7 @@
 	java/util/zip/Deflater.java \
 	java/util/zip/DeflaterOutputStream.java \
 	java/util/zip/Inflater.java \
-	java/util/zip/ZipEntry.java \
 	java/util/zip/ZipFile.java \
-	java/util/zip/ZipInputStream.java \
-	java/util/zip/ZipOutputStream.java \
 	org/kaffe/util/Assert.java \
 	org/kaffe/util/UTF8.java \
 	org/kaffe/util/zip/SwitchInflater.java 
Index: kaffe/libraries/javalib/zlib-zip/Makefile.in
diff -u kaffe/libraries/javalib/zlib-zip/Makefile.in:1.27 kaffe/libraries/javalib/zlib-zip/Makefile.in:1.28
--- kaffe/libraries/javalib/zlib-zip/Makefile.in:1.27	Tue Jan 22 23:21:47 2008
+++ kaffe/libraries/javalib/zlib-zip/Makefile.in	Thu Jan 31 20:49:48 2008
@@ -292,10 +292,7 @@
 	java/util/zip/Deflater.java \
 	java/util/zip/DeflaterOutputStream.java \
 	java/util/zip/Inflater.java \
-	java/util/zip/ZipEntry.java \
 	java/util/zip/ZipFile.java \
-	java/util/zip/ZipInputStream.java \
-	java/util/zip/ZipOutputStream.java \
 	org/kaffe/util/Assert.java \
 	org/kaffe/util/UTF8.java \
 	org/kaffe/util/zip/SwitchInflater.java 
===================================================================
Checking out kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipEntry.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/zlib-zip/java/util/zip/Attic/ZipEntry.java,v
VERS: 1.1
***************
--- kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipEntry.java	Thu Jan 31 20:51:15 2008
+++ /dev/null	Sun Aug  4 19:57:58 2002
@@ -1,246 +0,0 @@
-/*
- * Java core library component.
- *
- * Copyright (c) 1997, 1998
- *      Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- */
-
-package java.util.zip;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-
-public class ZipEntry implements Cloneable, ZipConstants {
-
-    /* Clone method taken from GNU Classpath:
-     * Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
-     */
-  /**
-   * Creates a copy of this zip entry.
-   */
-  /**
-   * Clones the entry.
-   */
-  public Object clone()
-  {
-    try
-      {
-	// The JCL says that the `extra' field is also copied.
-	ZipEntry clone = (ZipEntry) super.clone();
-	if (extra != null)
-	  clone.extra = (byte[]) extra.clone();
-	return clone;
-      }
-    catch (CloneNotSupportedException ex)
-      {
-	throw new InternalError();
-      }
-  }
-
-  public static final int STORED = Deflater.NO_COMPRESSION;
-  public static final int DEFLATED = Deflater.DEFLATED;
-
-  private String name;
-  private long time = -1;
-  int dosTime;
-  private long crc;
-  private long size;
-  private int method;
-  private byte[] extra;
-  private String comment;
-  int flag;
-  int version;
-  private long csize;
-  long offset;
-
-  /**
-   * this constructor is for internal library use only (makeZipEntry) 
-   */
-  ZipEntry()
-  {
-  }
-
-  public ZipEntry(String nm)
-  {
-    if (nm == null) {
-      throw new NullPointerException();
-    }
-    if (nm.length() > 0xFFFF) {
-      throw new IllegalArgumentException("name length > 0xFFFF");
-    }
-    name = nm;
-    time = new Date().getTime();
-    dosTime = computeDosTime(time);
-    crc = -1;
-    size = -1;
-    method = -1;
-    extra = null;
-    comment = null;
-    flag = 0;
-    version = 0;
-    csize = -1;
-    offset = 0;
-  }
-
-  /**
-   * Create a new ZipEntry with fields taken from the specified zip entry.
-   */
-  public ZipEntry(ZipEntry entry)
-  {
-    name = entry.name;
-    time = entry.time;
-    dosTime = entry.dosTime;
-    crc  = entry.crc;
-    size = entry.size;
-    method = entry.method;
-    extra = entry.extra;
-    comment = entry.comment;
-    flag = entry.flag;
-    version = entry.version;
-    csize = entry.csize;
-    offset = entry.offset;
-  }
-
-  public String getName()
-  {
-    return (name);
-  }
-
-  public void setTime(long tm)
-  {
-    time = tm;
-    dosTime = computeDosTime(tm);
-  }
-
-  public long getTime()
-  {
-    if (time == -1 && dosTime != 0)
-      setDosTime(dosTime);
-    return (time);
-  }
-
-  public void setSize(long size)
-  {
-    if (size < 0 || size > 0xFFFFFFFFL) {
-      throw new IllegalArgumentException("size < 0 or size > 0xFFFFFFFF");
-    }
-    this.size = size;
-  }
-
-  public long getSize()
-  {
-    return (size);
-  }
-
-  public void setCrc(long crcx)
-  {
-    if (crcx < 0 || crcx > 0xFFFFFFFFL) {
-      throw new IllegalArgumentException("crc < 0 or > 0xFFFFFFFF: " + crcx);
-    }
-    crc = crcx;
-  }
-
-  public long getCrc()
-  {
-    return (crc);
-  }
-
-  public void setMethod(int meth)
-  {
-    if (meth != STORED && meth != DEFLATED) {
-      throw new IllegalArgumentException("unsupported compression method");
-    }
-    method = meth;
-  }
-
-  public int getMethod()
-  {
-    return (method);
-  }
-
-  public void setExtra(byte extra[])
-  {
-    if ((extra != null) && (extra.length > 0xFFFFF)) {
-      throw new IllegalArgumentException("extra length > 0xFFFFF");
-    }
-    this.extra = extra;
-  }
-
-  public byte[] getExtra()
-  {
-    return (extra);
-  }
-
-  public void setComment(String comment)
-  {
-    if ((comment != null) && (comment.length() > 0xFFFF)) {
-      throw new IllegalArgumentException("comment length > 0xFFFF");
-    }
-    this.comment = comment;
-  }
-
-  public String getComment()
-  {
-    return (comment);
-  }
-
-  public void setCompressedSize(long csize)
-  {
-    if (csize < 0 || csize > 0xFFFFFFFFL) {
-	throw new IllegalArgumentException("csize < 0 or csize > 0xFFFFFFFF");
-    }
-
-    this.csize = csize;
-  }
-  
-  public long getCompressedSize()
-  {
-    return (csize);
-  }
-
-  public boolean isDirectory()
-  {
-    return (name.endsWith("/"));
-  }
-
-  public String toString()
-  {
-    return (getName());
-  }
-
-  // Encode timestamp in DOS format
-  int computeDosTime(long time) {
-    time = (time + 1) & ~1L; // Round up to even seconds.
-    Calendar cal = new GregorianCalendar();
-    cal.setTime(new Date(time));
-    return encodeDosTime(
-	cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1,
-	cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY),
-	cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
-  }
-
-  int encodeDosTime(int year, int month, int day, int hour,
-      int minute, int second) {
-    return (year < 1980) ? encodeDosTime(1980, 1, 1, 0, 0, 0) :
-      ((year - 1980) << 25) | (month << 21) | (day << 16) |
-      (hour << 11) | (minute << 5) | (second >>> 1);
-  }
-
-  void setDosTime(int date) {
-      Calendar cal = new GregorianCalendar();
-      cal.clear();
-      cal.set (((date >> 25) & 0x7F) + 1980,
-	       ((date >> 21) & 0xF) - 1,
-	       (date >> 16) & 0x1F,
-	       (date >> 11) & 0x1F,
-	       (date >> 5) & 0x3F,
-	       (date << 1) & 0x3E); 
-      time = cal.getTime().getTime();
-      dosTime = date;
-  }
-
-}
Index: kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipFile.java
diff -u kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipFile.java:1.1 kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipFile.java:1.2
--- kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipFile.java:1.1	Wed Aug  9 21:28:00 2006
+++ kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipFile.java	Thu Jan 31 20:49:48 2008
@@ -90,12 +90,17 @@
   return (all.elements());
 }
 
-public ZipEntry getEntry(String zname)
+private final ZipEntry getZipEntry(String zname)
 {
   checkIfClosed();
   return (getZipEntry0(zip, zname));
 }
 
+public ZipEntry getEntry(String zname)
+{
+    return (getZipEntry(zname));
+}
+
 public InputStream getInputStream(ZipEntry ze) throws IOException
 {
 	if (ze == null) {
@@ -103,7 +108,7 @@
 	}
 
 	if (ze.getSize() == -1) {
-		ze = getEntry(ze.getName());
+		ze = getZipEntry(ze.getName());
 	}
 
 	if (ze == null) {
===================================================================
Checking out kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipInputStream.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/zlib-zip/java/util/zip/Attic/ZipInputStream.java,v
VERS: 1.1
***************
--- kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipInputStream.java	Thu Jan 31 20:51:15 2008
+++ /dev/null	Sun Aug  4 19:57:58 2002
@@ -1,228 +0,0 @@
-
-/*
- * Java core library component.
- *
- * Copyright (c) 1997, 1998
- *      Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- */
-
-package java.util.zip;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-
-import org.kaffe.util.UTF8;
-import org.kaffe.util.zip.SwitchInflater;
-
-public class ZipInputStream extends InflaterInputStream
-	implements ZipConstants {
-
-  private byte sigbuf[] = new byte[4];
-  private byte zheader[] = new byte[LOCHDR];
-  private byte dheader[] = new byte[EXTHDR];
-  private boolean gotSig;
-  private SwitchInflater sinf;
-  private ZipEntry entry;
-
-  public ZipInputStream(InputStream in) {
-    super(in, new SwitchInflater(true, true));
-    sinf = (SwitchInflater)inf;
-    sinf.reset();
-    sinf.setMode(true);
-    sinf.setLength(Integer.MAX_VALUE);
-  }
-
-  public ZipEntry getNextEntry() throws IOException {
-
-    closeEntry();
-
-    synchronized (this) {
-
-      // First, open the stream.
-      sinf.setLength(Integer.MAX_VALUE);
-
-      // Read next signature
-      int sig = readSig();
-      switch (sig) {
-      case (int)CENSIG:		// central dir: no more entries
-	return null;
-      case (int)LOCSIG:		// another entry
-	break;
-      default:				// unexpected
-	return null;
-      }
-
-      // Read remainder of local header
-      readFully(zheader, sigbuf.length, zheader.length - sigbuf.length);
-
-      // Read filename; assume UTF-8 encoding
-      byte[] nameBuf = new byte[get16(zheader, LOCNAM)];
-      readFully(nameBuf, 0, nameBuf.length);
-
-      // Read extra field
-      byte[] extra = new byte[get16(zheader, LOCEXT)];
-      readFully(extra, 0, extra.length);
-
-      // Setup new entry
-      entry = createZipEntry(UTF8.decode(nameBuf));
-      entry.version = get16(zheader, LOCVER);
-      entry.flag    = get16(zheader, LOCFLG);
-
-      entry.setMethod(get16(zheader, LOCHOW));
-      entry.setDosTime(get32(zheader, LOCTIM));
-      entry.setCrc(get32(zheader, LOCCRC) & 0xffffffffL);
-
-      entry.setCompressedSize(get32(zheader, LOCSIZ) & 0xffffffffL);
-      entry.setSize(get32(zheader, LOCLEN) & 0xffffffffL);
-
-      entry.setExtra( extra );
-      entry.setComment("");
-      entry.offset = 0;
-
-      // Select the loader, simple or inflater.
-      if (entry.getMethod() == ZipEntry.STORED) {
-	sinf.setMode(true);
-	sinf.setLength((int)entry.getCompressedSize());
-      }
-      else {
-	sinf.setMode(false);
-      }
-
-      //System.out.println("ZipEntry (Post LOC): " + entry + ", meth="
-      // + entry.method + ", size=" + entry.size + ", csize=" + entry.csize
-      // + ", crc=" + entry.crc);
-
-      return entry;
-    }
-  }
-
-  public void closeEntry() throws IOException {
-    synchronized (this) {
-
-      // Don't do this twice
-      if (entry == null)
-	return;
-
-      // Cleanup
-      try {
-
-	// Skip remaining compressed data
-	byte[] buf = new byte[512];
-	while (read(buf, 0, buf.length) != -1);
-
-	// Reset inflate state machine
-	sinf.reset();
-	sinf.setMode(true);
-	sinf.setLength(Integer.MAX_VALUE);
-
-	// In the case where closeEntry() is called after reading
-	// a compressed entry, we need to read the DATA header that
-	// follows, if any, and update the ZipEntry with the info
-	// from the DATA header. This is so that users can find out
-	// the compressed and uncompressed sizes of data written in
-	// a compressed entry.
-	if (entry.getMethod() == ZipEntry.DEFLATED && peekSig() == (int)EXTSIG) {
-
-	  // Consume signature
-	  readSig();
-
-	  // Read remainder of data header
-	  readFully(dheader, sigbuf.length, dheader.length - sigbuf.length);
-
-	  // Read CRC
-	  int data_crc = get32(dheader, EXTCRC);
-	  entry.setCrc(data_crc & 0xffffffffL);
-
-	  // Read compressed size
-	  int data_csize = get32(dheader, EXTSIZ);
-	  entry.setCompressedSize(data_csize & 0xffffffffL);
-
-	  // Read uncompressed size
-	  int data_size = get32(dheader, EXTLEN);
-	  if (data_crc == 0 && data_size != 0) {
-	      throw new IOException(
-		"CRC error: data_crc=0, data_csize=" + data_csize + ",data_size=" + data_size);
-	  }
-	  entry.setSize(data_size & 0xffffffffL);
-
-	  //System.out.println("ZipEntry (Post DATA): " + entry
-	  // + ", meth=" + entry.method + ", size=" + entry.size
-	  // + ", csize=" + entry.csize + ", crc=" + entry.crc);
-	}
-	
-	// Close the input stream for the rest of the world.
-	sinf.setLength(0);
-      } finally {
-	entry = null;
-      }
-    }
-  }
-
-  public int read(byte[] b, int off, int len) throws IOException {
-    return super.read(b, off, len);
-  }
-
-  public long skip(long n) throws IOException {
-    return super.skip(n);
-  }
-
-  public void close() throws IOException {
-    closeEntry();
-    super.close();
-    // Now completely close the byte stream. There may be some
-    // bytes left in the buffer.
-    sinf.setInput(null, 0, 0);
-  }
-
-  private int get16(byte[] buf, int base) {
-    int val = (int)buf[base] & 0xFF;
-    val |= ((int)buf[base+1] & 0xFF) << 8;
-    return (val);
-  }
-
-  private int get32(byte[] buf, int base) {
-    return  buf[base] & 0xFF
-	| ((buf[base+1] & 0xFF) << 8)
-	| ((buf[base+2] & 0xFF) << 16)
-	| ((buf[base+3] & 0xFF) << 24);
-  }
-
-  private void readFully(byte[] buf, int off, int len) throws IOException {
-    int nread;
-
-    for (int remain = len; remain > 0; remain -= nread) {
-      nread = read(buf, off, remain);
-      if (nread == -1) {
-	if (remain != 0) {
-	  throw new IOException("truncated file (only read "
-	    + (len - remain) + "/" + len + ")");
-	}
-	return;
-      }
-      off += nread;
-    }
-  }
-
-  private int readSig() throws IOException {
-    int sig = peekSig();
-    gotSig = false;
-    return sig;
-  }
-
-  private int peekSig() throws IOException {
-    if (!gotSig) {
-      readFully(sigbuf, 0, sigbuf.length);
-      gotSig = true;
-    }
-    return get32(sigbuf, 0);
-  }
-
-  protected ZipEntry createZipEntry(String name) {
-	return new ZipEntry(name);
-  }
-}
-
===================================================================
Checking out kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipOutputStream.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/zlib-zip/java/util/zip/Attic/ZipOutputStream.java,v
VERS: 1.1
***************
--- kaffe/libraries/javalib/zlib-zip/java/util/zip/ZipOutputStream.java	Thu Jan 31 20:51:15 2008
+++ /dev/null	Sun Aug  4 19:57:58 2002
@@ -1,349 +0,0 @@
-/*
- * Java core library component.
- *
- * Copyright (c) 1997, 1998
- *      Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- */
-
-package java.util.zip;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Enumeration;
-import java.util.Vector;
-
-import org.kaffe.util.UTF8;
-
-// Reference: ftp://ftp.uu.net/pub/archiving/zip/doc/appnote-970311-iz.zip
-
-public class ZipOutputStream extends DeflaterOutputStream
-	implements ZipConstants {
-
-  public static final int STORED = Deflater.NO_COMPRESSION;
-  public static final int DEFLATED = Deflater.DEFLATED;
-
-private static final int ZIPVER_1_0 = 0x000a;
-private static final int ZIPVER_2_0 = 0x0014;
-
-    /* Copied the fields over from GNU Claspath to make it compile again */
-  /* The following two fields are missing in SUN JDK */
-  private final int ENDNRD =  4;
-  private final int ENDDCD =  6;
-
-private int method = Deflater.DEFLATED;
-private int level = Deflater.DEFAULT_COMPRESSION;
-private ZipEntry curr;
-private Vector dir;
-private OutputStream strm;
-private int dout;
-private CRC32 crc;
-
-class Storer
-  extends Deflater {
-
-private int total;
-private byte[] buf;
-private int off;
-private int len;
-
-Storer() {
-    total = 0;
-    off = 0;
-    len = 0;
-}
-
-public int deflate(byte[] b, int p, int l) {
-	if (l >= len) {
-		l = len;
-	}
-	System.arraycopy(buf, off, b, p, l);
-	total += l;
-	off += l;
-	len -= l;
-	return (l);
-}
-
-public synchronized void setInput(byte b[], int o, int l)
-{
-	buf = b;
-	off = o;
-	len = l;
-}
-
-public boolean needsInput() {
-	return (len > 0 ? false : true);
-}
-
-public boolean finished() {
-	return (len > 0 ? false : true);
-}
-
-public int getTotalIn() {
-	return (total);
-}
-
-public int getTotalOut() {
-	return (total);
-}
-
-public void reset() {
-}
-
-}
-
-public ZipOutputStream(OutputStream out)
-{
-	super(out);
-	strm = out;
-	curr = null;
-	dir = new Vector();
-	dout = 0;
-	crc = new CRC32();
-}
-
-public void close() throws IOException
-{
-	finish();
-	super.close();
-}
-
-public void closeEntry() throws IOException
-{
-	if (curr == null) {
-		return;

*** Patch too long, truncated ***




More information about the kaffe mailing list