You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Luís Filipe Nassif <lf...@gmail.com> on 2018/07/04 19:56:16 UTC

[compress] Problem setting ZipEntry extended timestamps

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

Re: [compress] Problem setting ZipEntry extended timestamps

Posted by Stefan Bodewig <bo...@apache.org>.
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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [compress] Problem setting ZipEntry extended timestamps

Posted by Luís Filipe Nassif <lf...@gmail.com>.
 X000A_NTFS  worked for 7zip!

Thanks

2018-07-05 8:17 GMT-03:00 Luís Filipe Nassif <lf...@gmail.com>:

> Thank you, Stefan.
>
> Luis
>
> 2018-07-05 6:25 GMT-03:00 Stefan Bodewig <bo...@apache.org>:
>
>> 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: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>

Re: [compress] Problem setting ZipEntry extended timestamps

Posted by Luís Filipe Nassif <lf...@gmail.com>.
Thank you, Stefan.

Luis

2018-07-05 6:25 GMT-03:00 Stefan Bodewig <bo...@apache.org>:

> 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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [compress] Problem setting ZipEntry extended timestamps

Posted by Gary Gregory <ga...@gmail.com>.
Let's update to Java 8.

Gary

On Thu, Jul 5, 2018, 03:25 Stefan Bodewig <bo...@apache.org> 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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [compress] Problem setting ZipEntry extended timestamps

Posted by Stefan Bodewig <bo...@apache.org>.
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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org