[compress] Problem setting ZipEntry extended timestamps

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[compress] Problem setting ZipEntry extended timestamps

Luís Filipe Nassif
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
Reply | Threaded
Open this post in threaded view
|

Re: [compress] Problem setting ZipEntry extended timestamps

Stefan Bodewig
On 2018-07-04, Luís Filipe Nassif wrote:

> 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,

...

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

...

> 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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [compress] Problem setting ZipEntry extended timestamps

Luís Filipe Nassif
Thank you, Stefan.

Luis

2018-07-05 6:25 GMT-03:00 Stefan Bodewig <[hidden email]>:

> On 2018-07-04, Luís Filipe Nassif wrote:
>
> > 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,
>
> ...
>
> > entry.setLastAccessTime(FileTime.fromMillis(System.
> currentTimeMillis()));
>
> ...
>
> > 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: [compress] Problem setting ZipEntry extended timestamps

Luís Filipe Nassif
 X000A_NTFS  worked for 7zip!

Thanks

2018-07-05 8:17 GMT-03:00 Luís Filipe Nassif <[hidden email]>:

> Thank you, Stefan.
>
> Luis
>
> 2018-07-05 6:25 GMT-03:00 Stefan Bodewig <[hidden email]>:
>
>> On 2018-07-04, Luís Filipe Nassif wrote:
>>
>> > 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,
>>
>> ...
>>
>> > entry.setLastAccessTime(FileTime.fromMillis(System.currentTi
>> meMillis()));
>>
>> ...
>>
>> > 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: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: [compress] Problem setting ZipEntry extended timestamps

Stefan Bodewig
On 2018-07-05, Luís Filipe Nassif wrote:

>  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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [compress] Problem setting ZipEntry extended timestamps

garydgregory
In reply to this post by Stefan Bodewig
Let's update to Java 8.

Gary

On Thu, Jul 5, 2018, 03:25 Stefan Bodewig <[hidden email]> wrote:

> On 2018-07-04, Luís Filipe Nassif wrote:
>
> > 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,
>
> ...
>
> > entry.setLastAccessTime(FileTime.fromMillis(System.currentTimeMillis()));
>
> ...
>
> > 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>