-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
1.4.2
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
EXTRA RELEVANT SYSTEM CONFIGURATION :
NTFS file system
A DESCRIPTION OF THE PROBLEM :
Using java.util.zip.ZipEntry to set and get the time of the entries.
ZipEntry.setTime(X) works correctly. (Checked via 3rd party zip program).
However, when using ZipEntry.getTime() it returns the time of the ZipFile, not the time of the Entry in the ZipFile.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a zip file add entries and set their time stamps.
See source code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
for every file passed to the method you should get 2 statements on the console:
[filename] PreZip: [filetimeinMS]
InZip: [entrytimeinMS]
ie.
c:\test.txt PreZip: 1121699509549
InZip: 1121699509549
ACTUAL -
c:\test.txt PreZip: 1121699509549
InZip: 1121699508000
the 2 times should be identical, however, [entrytimeinMS] will be the time of the ZipFile instead. If you open said ZipFile with WinZip etc, the time reported by them for the entries will be correct.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.zip.*;
import java.io.*;
class test
{
public static void main(String[] args)
{
String con[] = { "File1", "File2" };
test t = new test();
t.createZip("test.zip", con);
}
public void createZip(String zipfilename, String[] contents) {
try {
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipfilename));
for (int i=0; i<contents.length; i++) {
ZipEntry ze = new ZipEntry(contents[i]);
zos.setMethod(ZipOutputStream.DEFLATED); //indicate deflated
zos.setLevel(Deflater.DEFAULT_COMPRESSION); //use default level
zos.putNextEntry(ze);
File fin = new File(contents[i]);
FileInputStream ins = new FileInputStream(fin);
System.out.println(contents[i] + " PreZip: " + fin.lastModified());
ze.setTime(fin.lastModified());
System.out.println("InZip: " + ze.getTime());
int bread;
byte[] bin = new byte[4096];
while ( (bread = ins.read(bin, 0, 4096)) > -1) {
zos.write(bin, 0, bread); }
zos.closeEntry();
}
zos.close();
}
catch (Exception x) {
System.out.println(x.toString());
}
}
}
---------- END SOURCE ----------
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
EXTRA RELEVANT SYSTEM CONFIGURATION :
NTFS file system
A DESCRIPTION OF THE PROBLEM :
Using java.util.zip.ZipEntry to set and get the time of the entries.
ZipEntry.setTime(X) works correctly. (Checked via 3rd party zip program).
However, when using ZipEntry.getTime() it returns the time of the ZipFile, not the time of the Entry in the ZipFile.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a zip file add entries and set their time stamps.
See source code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
for every file passed to the method you should get 2 statements on the console:
[filename] PreZip: [filetimeinMS]
InZip: [entrytimeinMS]
ie.
c:\test.txt PreZip: 1121699509549
InZip: 1121699509549
ACTUAL -
c:\test.txt PreZip: 1121699509549
InZip: 1121699508000
the 2 times should be identical, however, [entrytimeinMS] will be the time of the ZipFile instead. If you open said ZipFile with WinZip etc, the time reported by them for the entries will be correct.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.zip.*;
import java.io.*;
class test
{
public static void main(String[] args)
{
String con[] = { "File1", "File2" };
test t = new test();
t.createZip("test.zip", con);
}
public void createZip(String zipfilename, String[] contents) {
try {
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipfilename));
for (int i=0; i<contents.length; i++) {
ZipEntry ze = new ZipEntry(contents[i]);
zos.setMethod(ZipOutputStream.DEFLATED); //indicate deflated
zos.setLevel(Deflater.DEFAULT_COMPRESSION); //use default level
zos.putNextEntry(ze);
File fin = new File(contents[i]);
FileInputStream ins = new FileInputStream(fin);
System.out.println(contents[i] + " PreZip: " + fin.lastModified());
ze.setTime(fin.lastModified());
System.out.println("InZip: " + ze.getTime());
int bread;
byte[] bin = new byte[4096];
while ( (bread = ins.read(bin, 0, 4096)) > -1) {
zos.write(bin, 0, bread); }
zos.closeEntry();
}
zos.close();
}
catch (Exception x) {
System.out.println(x.toString());
}
}
}
---------- END SOURCE ----------
- relates to
-
JDK-6303183 Support NTFS and Unix-style timestamps for entries in Zip files
-
- Closed
-