creating identical zip archives with java and zip tools
Hi,
a simple problem: we have JavaEE based server that accepts ZIP files,
and a JavaEE based client that creates and uploads them. We verify
that the ZIP file is identical at client and server by MD5.
I'd like to write a client with some other language.. in fact even a
shell/wget script would do. But here's the problem: if I create a ZIP
archive with java.util.zip, it is not the identical to an archive
created by command line tools. Here's a simple example:
cat hello.txt
hello
zip hello1.zip hello.txt
java makezip
[creates hello2.zip, code below]
ls -l hello1.zip hello2.zip
-rw-r--r-- 1 x x 174 2010-08-24 12:23 hello1.zip
-rw-r--r-- 1 x x 140 2010-08-24 12:24 hello2.zip
Is there a way of forcing compatibility on either the zip tool (on
Linux) or Java?
TIA,
Mark
import java.io.*;
import java.util.zip.*;
public class makezip {
public static void main(String[] args) {
String file_to_add = "hello.txt";
byte[] buf = new byte[1024];
try {
String outFilename = "hello2.zip";
ZipOutputStream out = new ZipOutputStream(new
FileOutputStream(outFilename));
FileInputStream in = new FileInputStream(file_to_add);
// Add ZIP entry to output
stream.
out.putNextEntry(new ZipEntry(file_to_add));
int len;
while ((len = in.read(buf)) > 0) { out.write(buf, 0,
len); }
out.closeEntry(); in.close();
out.close();
} catch (IOException e) { }
}
}