From: Erik on
ZipOutputStream: if I put an uncompressed file named "mimetype" into
the zip and the content of the file is "application/html+zip", there
are 5 bytes between the filename and the content:

01 14 00 EB FF

Normally (in Winzip), uncompressed content immediately follows the
filename, shows WinZIP. What are those 5 bytes for and how can I do
things the WinZIP way ?
In other words, I want to get rid of those 5 bytes when building my
ZIP file.
Is there some setting for this in the class ?
From: Erik on
Some additional info from WinZIP about the Java-generated zip file:


Central directory entry PK0102 (4+42): #1
======================================
part number in which file begins (0000): 1
relative offset of local header: 0 (0x00000000)
bytes
version made by operating system (00): MS-DOS, OS/2, NT
FAT
version made by zip software (20): 2.0
operat. system version needed to extract (00): MS-DOS, OS/2, NT
FAT
unzip software version needed to extract (20): 2.0
general purpose bit flag (0x0008) (bit 15..0): 0000.0000
0000.1000
file security status (bit 0): not encrypted
extended local header (bit 3): yes
compression method (08): deflated
compression sub-type (deflation): normal
file last modified on (0x00003c39 0x0000b52a): 2010-01-25
22:41:20
32-bit CRC value: 0x2cab616f
compressed size: 25 bytes <<====
uncompressed size: 20 bytes
length of filename: 8 characters
length of extra field: 0 bytes
length of file comment: 0 characters
internal file attributes: 0x0000
apparent file type: binary
external file attributes: 0x00000000
non-MSDOS external file attributes: 0x000000
MS-DOS file attributes (0x00): none
Current Location part 1 offset 1369563
filename:mimetype

From: Erik on
problem solved. This is how it must be done:

public void create(ArrayList<FileItem> list,String path, String
fileName) {

// Create a buffer for reading the files
byte[] buf = new byte[1024];
System.out.print("Create " + fileName + ": ");
try {

ZipOutputStream out = new ZipOutputStream(new
FileOutputStream(path + fileName));
out.setMethod(ZipOutputStream.DEFLATED); // file mimetype
must be uncompressed
out.setLevel(Deflater.DEFAULT_COMPRESSION);
// Compress the files
for (FileItem fi : list) {
String fn = fi.dir + fi.fileName;

FileInputStream in = new
FileInputStream(root.getPath() + "\\" + fn);

// Add ZIP entry to output stream.
ZipEntry z = new ZipEntry(fn);
if (fn.equals("mimetype")) {

z.setMethod(ZipOutputStream.STORED); // file
mimetype must be uncompressed
// These three MUST be set. However, I think they may be set to
anything...
z.setSize(20); // length of data
z.setCompressedSize(20);
z.setCrc(0x2cab616f);
}
else {
z.setMethod(ZipOutputStream.DEFLATED);
}

out.putNextEntry(z);

// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}

// Complete the entry
out.closeEntry();
in.close();

}

// Complete the ZIP file
out.close();
System.out.println("OK.");
}
catch (IOException e) {
System.out.println(e.getMessage());
}
}

From: Roedy Green on
On Mon, 25 Jan 2010 23:16:18 +0100, Erik <et57(a)hotmail.com> wrote,
quoted or indirectly quoted someone who said :

>ZipOutputStream: if I put an uncompressed file named "mimetype" into
>the zip and the content of the file is "application/html+zip", there
>are 5 bytes between the filename and the content:

ZIP format goes back to the DOS days. Originally file names were
ASCII. I suspect there is some kludge in effect for filenames with a
"weird" character like +, rather than simple UTF-8.

The ZIP format is documented at PkZip.com. See
http://mindprod.com/jgloss/zip.html

You might learn something looking at Sun's code. It may be native at
the low level though.

WinZip people relatively recently started supporting Unicode
filenames. I don't know how they are encoded internally.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Don�t be discouraged by a failure. It can be a positive experience. Failure is, in a sense, the highway to success, inasmuch as every discovery of what is false leads us to seek earnestly after what is true, and every fresh experience points out some form of error which we shall afterwards carefully avoid.
~ John Keats (born: 1795-10-31 died: 1821-02-23 at age: 25)
From: Roedy Green on
On Mon, 25 Jan 2010 23:41:35 +0100, Erik <et57(a)hotmail.com> wrote,
quoted or indirectly quoted someone who said :

> file last modified on (0x00003c39 0x0000b52a): 2010-01-25

One problem with ZIP format that bedevils me is that when you put a
file into a zip, then restore it, the timestamp can be out by up to 2
seconds! The restored file looks like a DIFFERENT version of the file.

Further the timestamps are in local timezone rather than GMT, and the
timezone is not recorded. Arrgh. I have been bugging the Winzip and
the Truezip people to fix this.

Vendors are reluctant, I think, primarily because an upward compatible
solution would make files fatter. Archivers compete ferociously.

http://mindprod.com/jgloss/compressionutilities.html.

The evil that men do lives after them. The good is oft interred with
their bones.
~ William Shakespear (born: 1564-04-23 died: 1616-04-23 at age: 52)
Julius Caesar Act II scene ii

--
Roedy Green Canadian Mind Products
http://mindprod.com
Don�t be discouraged by a failure. It can be a positive experience. Failure is, in a sense, the highway to success, inasmuch as every discovery of what is false leads us to seek earnestly after what is true, and every fresh experience points out some form of error which we shall afterwards carefully avoid.
~ John Keats (born: 1795-10-31 died: 1821-02-23 at age: 25)