Discussion:
[compress] Problem setting ZipEntry extended timestamps
(too old to reply)
Luís Filipe Nassif
2018-07-04 19:56:16 UTC
Permalink
Hi,

I am trying to create a zip file saving its entries accessTime and
CreationTime, but when I open the zip file with 7zip, those dates are not
shown, only modifiedTime. I am using compress-1.16.1. Sample code below
(without exception handling):

FileOutputStream fos = new FileOutputStream("F:\\test.zip");
ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(fos);

ZipArchiveEntry entry = new ZipArchiveEntry("file.txt");


entry.setLastModifiedTime(FileTime.fromMillis(System.currentTimeMillis()));

entry.setLastAccessTime(FileTime.fromMillis(System.currentTimeMillis()));

entry.setCreationTime(FileTime.fromMillis(System.currentTimeMillis()));

zaos.putArchiveEntry(entry);

byte[] buf = "content".getBytes("UTF-8");
zaos.write(buf, 0, buf.length);

zaos.closeArchiveEntry();

zaos.close();

Any idea why it does not work?

Thanks,
Luis
Luís Filipe Nassif
2018-07-04 20:08:44 UTC
Permalink
Hi,

I am trying to create a zip file saving its entries accessTime and
CreationTime, but when I open the zip file with 7zip, those dates are not
shown, only modifiedTime. I am using compress-1.16.1. Sample code below
(without exception handling):

FileOutputStream fos = new FileOutputStream("F:\\test.zip");
ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(fos);

ZipArchiveEntry entry = new ZipArchiveEntry("file.txt");

entry.setLastModifiedTime(FileTime.fromMillis(System.
currentTimeMillis()));
entry.setLastAccessTime(FileTime.fromMillis(System.
currentTimeMillis()));
entry.setCreationTime(FileTime.fromMillis(System.
currentTimeMillis()));

zaos.putArchiveEntry(entry);

byte[] buf = "content".getBytes("UTF-8");
zaos.write(buf, 0, buf.length);

zaos.closeArchiveEntry();

zaos.close();

Any idea why it does not work?

Thanks,
Luis
Stefan Bodewig
2018-07-05 09:25:08 UTC
Permalink
Post by Luís Filipe Nassif
I am trying to create a zip file saving its entries accessTime and
CreationTime, but when I open the zip file with 7zip, those dates are not
shown,
...
Post by Luís Filipe Nassif
entry.setLastAccessTime(FileTime.fromMillis(System.currentTimeMillis()));
...
Post by Luís Filipe Nassif
Any idea why it does not work?
Commons Compress' ZipArchiveEntry inherits this method from ZipEntry. It
was added in Java8 and as Commons Compress currently targets Java7 we
haven't added any support for the new fields, yet.

Basically our code base doesn't know you have set the values at all.

The way you set the dates using Commons Compress' API is by creating a
X5455_ExtendedTimestamp extra field and attaching it to the
ZipArchiveEntry. If you want to be extra sure you create an additional
X000A_NTFS extra field. I'm not sure which of the two (maybe both?)
Java8 would use or which one 7z would consult (InfoZIP only uses the
ExtendedTimestamp IIRC).

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@commons.apache.org
For additional commands, e-mail: user-***@commons.apache.org
Luís Filipe Nassif
2018-07-05 11:17:40 UTC
Permalink
Thank you, Stefan.

Luis
Post by Luís Filipe Nassif
Post by Luís Filipe Nassif
I am trying to create a zip file saving its entries accessTime and
CreationTime, but when I open the zip file with 7zip, those dates are not
shown,
...
Post by Luís Filipe Nassif
entry.setLastAccessTime(FileTime.fromMillis(System.
currentTimeMillis()));
...
Post by Luís Filipe Nassif
Any idea why it does not work?
Commons Compress' ZipArchiveEntry inherits this method from ZipEntry. It
was added in Java8 and as Commons Compress currently targets Java7 we
haven't added any support for the new fields, yet.
Basically our code base doesn't know you have set the values at all.
The way you set the dates using Commons Compress' API is by creating a
X5455_ExtendedTimestamp extra field and attaching it to the
ZipArchiveEntry. If you want to be extra sure you create an additional
X000A_NTFS extra field. I'm not sure which of the two (maybe both?)
Java8 would use or which one 7z would consult (InfoZIP only uses the
ExtendedTimestamp IIRC).
Stefan
---------------------------------------------------------------------
Luís Filipe Nassif
2018-07-05 12:40:40 UTC
Permalink
X000A_NTFS worked for 7zip!

Thanks
Post by Luís Filipe Nassif
Thank you, Stefan.
Luis
Post by Luís Filipe Nassif
Post by Luís Filipe Nassif
I am trying to create a zip file saving its entries accessTime and
CreationTime, but when I open the zip file with 7zip, those dates are
not
Post by Luís Filipe Nassif
shown,
...
Post by Luís Filipe Nassif
entry.setLastAccessTime(FileTime.fromMillis(System.currentTi
meMillis()));
...
Post by Luís Filipe Nassif
Any idea why it does not work?
Commons Compress' ZipArchiveEntry inherits this method from ZipEntry. It
was added in Java8 and as Commons Compress currently targets Java7 we
haven't added any support for the new fields, yet.
Basically our code base doesn't know you have set the values at all.
The way you set the dates using Commons Compress' API is by creating a
X5455_ExtendedTimestamp extra field and attaching it to the
ZipArchiveEntry. If you want to be extra sure you create an additional
X000A_NTFS extra field. I'm not sure which of the two (maybe both?)
Java8 would use or which one 7z would consult (InfoZIP only uses the
ExtendedTimestamp IIRC).
Stefan
---------------------------------------------------------------------
Stefan Bodewig
2018-07-05 13:03:27 UTC
Permalink
Post by Luís Filipe Nassif
X000A_NTFS worked for 7zip!
Great.

I've opened https://issues.apache.org/jira/browse/COMPRESS-458 but it
will have to wait for Compress to be based on Java8.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@commons.apache.org
For additional commands, e-mail: user-***@commons.apache.org
Gary Gregory
2018-07-05 13:08:54 UTC
Permalink
Let's update to Java 8.

Gary
Post by Stefan Bodewig
Post by Luís Filipe Nassif
I am trying to create a zip file saving its entries accessTime and
CreationTime, but when I open the zip file with 7zip, those dates are not
shown,
...
Post by Luís Filipe Nassif
entry.setLastAccessTime(FileTime.fromMillis(System.currentTimeMillis()));
...
Post by Luís Filipe Nassif
Any idea why it does not work?
Commons Compress' ZipArchiveEntry inherits this method from ZipEntry. It
was added in Java8 and as Commons Compress currently targets Java7 we
haven't added any support for the new fields, yet.
Basically our code base doesn't know you have set the values at all.
The way you set the dates using Commons Compress' API is by creating a
X5455_ExtendedTimestamp extra field and attaching it to the
ZipArchiveEntry. If you want to be extra sure you create an additional
X000A_NTFS extra field. I'm not sure which of the two (maybe both?)
Java8 would use or which one 7z would consult (InfoZIP only uses the
ExtendedTimestamp IIRC).
Stefan
---------------------------------------------------------------------
Loading...