Here's another fix for a problem regarding the creation of zip files. Kaffe
fails to create compressed zip files. apart from the diff, I have included a
small test program to reproduce the bug and test the fix.
Index: DeflaterOutputStream.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/util/zip/DeflaterOutputStream.java,v
retrieving revision 1.4
diff -u -r1.4 DeflaterOutputStream.java
--- DeflaterOutputStream.java 2001/03/07 03:27:43 1.4
+++ DeflaterOutputStream.java 2001/05/06 21:22:35
@@ -62,8 +62,11 @@
public void write(byte b[], int off, int len) throws IOException {
if (off < 0 || len < 0 || off + len > b.length)
throw new IndexOutOfBoundsException();
- def.setInput(b, off, len);
- deflate();
+
+ if(len != 0) {
+ def.setInput(b, off, len);
+ deflate();
+ }
}
public void write(int b) throws IOException {
import java.io.*;
import java.util.zip.*;
public class ZipTest {
public static void main(String[] args)
throws Exception
{
buildZip("ziptest1.zip", false);
buildZip("ziptest2.zip", true);
}
static void buildZip(String zipFile, boolean compress)
throws Exception
{
System.out.println("****");
System.out.print("Creating " + zipFile + " (");
if(!compress)
System.out.print("un");
System.out.println("compressed)");
ZipOutputStream zOut = new ZipOutputStream(new FileOutputStream(zipFile));
if(compress)
zOut.setMethod(ZipOutputStream.DEFLATED);
else
zOut.setMethod(ZipOutputStream.STORED);
addFile(zOut, "ZipTest.class", compress);
if(zOut != null)
zOut.close();
}
static void addFile(ZipOutputStream zOut, String file, boolean compress)
throws Exception
{
InputStream in = new FileInputStream(file);
ZipEntry ze = new ZipEntry(file);
if(!compress) {
long size = 0;
CRC32 cal = new CRC32();
if(!in.markSupported()) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[8 * 1024];
int count = 0;
do {
size += count;
cal.update(buffer, 0, count);
bos.write(buffer, 0, count);
count = in.read(buffer, 0, buffer.length);
}
while(count != -1);
in = new ByteArrayInputStream(bos.toByteArray());
}
else {
in.mark(Integer.MAX_VALUE);
byte[] buffer = new byte[8 * 1024];
int count = 0;
do {
size += count;
cal.update(buffer, 0, count);
count = in.read(buffer, 0, buffer.length);
}
while(count != -1);
in.reset();
}
ze.setSize(size);
ze.setCrc(cal.getValue());
}
zOut.putNextEntry(ze);
byte[] buffer = new byte[8 * 1024];
int count = 0;
do {
zOut.write(buffer, 0, count);
count = in.read(buffer, 0, buffer.length);
}
while(count != -1);
}
}