You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Kristina Chodorow <kc...@google.com> on 2015/06/10 16:08:40 UTC
[compress] Getting external attributes from a ZipArchiveEntry
ZipArchiveEntry.getExternalAttributes() is always returning 0 for me. I
have pasted a hex dump of the zip file I'm testing with at the bottom of
email: 2 files of 0 bytes, one named x and one named y. Both of their
external attributes are 33184 (a081 in the hex dump). However, running the
following program gives me 0 for both of their external attributes:
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
public class Foo {
public static void main(String args[]) throws IOException {
File archiveFile = new File("myzip.zip");
try (InputStream is = new FileInputStream(archiveFile)) {
ZipArchiveInputStream in = new ZipArchiveInputStream(is);
ZipArchiveEntry entry = in.getNextZipEntry();
while (entry != null) {
System.out.println("entry: " + entry);
System.out.println("external: " + entry.getExternalAttributes());
entry = in.getNextZipEntry();
}
}
}
}
Do I need to do something different to get the external attributes? Is
this a bug?
Hex dump of myzip.zip:
87654321 0011 2233 4455 6677 8899 aabb ccdd eeff 0123456789abcdef
00000000: 504b 0304 0a00 0000 0000 c766 c946 0000 PK.........f.F..
00000010: 0000 0000 0000 0000 0000 0100 1c00 7855 ..............xU
00000020: 5409 0003 361a 7733 441a 7755 7578 0b00 T...6.w3D.wUux..
00000030: 0104 2c03 0300 0488 1300 0050 4b03 040a ..,........PK...
00000040: 0000 0000 00c7 66c9 4600 0000 0000 0000 ......f.F.......
00000050: 0000 0000 0001 001c 0079 5554 0900 0336 .........yUT...6
00000060: 1a77 5544 1a77 5575 780b 0001 042c 0303 .wUD.wUux....,..
00000070: 0004 8813 0000 504b 0102 1e03 0a00 0000 ......PK........
00000080: 0000 c766 c946 0000 0000 0000 0000 0000 ...f.F..........
00000090: 0000 0100 1800 0000 0000 0000 0000 a081 ................
000000a0: 0000 0000 7855 5405 0003 361a 7755 7578 ....xUT...6.wUux
000000b0: 0b00 0104 2c03 0300 0488 1300 0050 4b01 ....,........PK.
000000c0: 021e 030a 0000 0000 00c7 66c9 4600 0000 ..........f.F...
000000d0: 0000 0000 0000 0000 0001 0018 0000 0000 ................
000000e0: 0000 0000 00a0 813b 0000 0079 5554 0500 .......;...yUT..
000000f0: 0336 1a77 5575 780b 0001 042c 0303 0004 .6.wUux....,....
00000100: 8813 0000 504b 0506 0000 0000 0200 0200 ....PK..........
00000110: 8e00 0000 7600 0000 0000 ....v.....
Re: [compress] Getting external attributes from a ZipArchiveEntry
Posted by Gary Gregory <ga...@gmail.com>.
I probably create a JIRA and attach the relevant files.
Gary
On Wed, Jun 10, 2015 at 7:08 AM, Kristina Chodorow <kc...@google.com>
wrote:
> ZipArchiveEntry.getExternalAttributes() is always returning 0 for me. I
> have pasted a hex dump of the zip file I'm testing with at the bottom of
> email: 2 files of 0 bytes, one named x and one named y. Both of their
> external attributes are 33184 (a081 in the hex dump). However, running the
> following program gives me 0 for both of their external attributes:
>
> import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
> import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
>
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.InputStream;
> import java.io.IOException;
>
> public class Foo {
> public static void main(String args[]) throws IOException {
> File archiveFile = new File("myzip.zip");
> try (InputStream is = new FileInputStream(archiveFile)) {
> ZipArchiveInputStream in = new ZipArchiveInputStream(is);
> ZipArchiveEntry entry = in.getNextZipEntry();
> while (entry != null) {
> System.out.println("entry: " + entry);
> System.out.println("external: " + entry.getExternalAttributes());
> entry = in.getNextZipEntry();
> }
> }
> }
> }
>
> Do I need to do something different to get the external attributes? Is
> this a bug?
>
> Hex dump of myzip.zip:
>
> 87654321 0011 2233 4455 6677 8899 aabb ccdd eeff 0123456789abcdef
>
>
> 00000000: 504b 0304 0a00 0000 0000 c766 c946 0000 PK.........f.F..
> 00000010: 0000 0000 0000 0000 0000 0100 1c00 7855 ..............xU
> 00000020: 5409 0003 361a 7733 441a 7755 7578 0b00 T...6.w3D.wUux..
> 00000030: 0104 2c03 0300 0488 1300 0050 4b03 040a ..,........PK...
> 00000040: 0000 0000 00c7 66c9 4600 0000 0000 0000 ......f.F.......
> 00000050: 0000 0000 0001 001c 0079 5554 0900 0336 .........yUT...6
> 00000060: 1a77 5544 1a77 5575 780b 0001 042c 0303 .wUD.wUux....,..
> 00000070: 0004 8813 0000 504b 0102 1e03 0a00 0000 ......PK........
> 00000080: 0000 c766 c946 0000 0000 0000 0000 0000 ...f.F..........
> 00000090: 0000 0100 1800 0000 0000 0000 0000 a081 ................
> 000000a0: 0000 0000 7855 5405 0003 361a 7755 7578 ....xUT...6.wUux
> 000000b0: 0b00 0104 2c03 0300 0488 1300 0050 4b01 ....,........PK.
> 000000c0: 021e 030a 0000 0000 00c7 66c9 4600 0000 ..........f.F...
> 000000d0: 0000 0000 0000 0000 0001 0018 0000 0000 ................
> 000000e0: 0000 0000 00a0 813b 0000 0079 5554 0500 .......;...yUT..
> 000000f0: 0336 1a77 5575 780b 0001 042c 0303 0004 .6.wUux....,....
> 00000100: 8813 0000 504b 0506 0000 0000 0200 0200 ....PK..........
> 00000110: 8e00 0000 7600 0000 0000 ....v.....
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: [compress] Getting external attributes from a ZipArchiveEntry
Posted by Stefan Bodewig <bo...@apache.org>.
On 2015-06-11, Gary Gregory wrote:
> On Wed, Jun 10, 2015 at 9:29 PM, Stefan Bodewig <bo...@apache.org> wrote:
>> External attributes are stored inside the central directory which is
>> at the end of the archive. When using ZipArchiveInputStream the
>> central directory is only ever reached once all entries have been
>> read.
>> If you need to access the information from the central directory you
>> should use ZipFile rather than ZipArchiveInputStream.
> Is that in the Javadoc?
No, not explicitly.
<http://commons.apache.org/proper/commons-compress/zip.html#ZipArchiveInputStream_vs_ZipFile>
and the very first point in
<http://commons.apache.org/proper/commons-compress/limitations.html#ZIP>
I'll open a JIRA issue to track the lack of information in the javadocs.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [compress] Getting external attributes from a ZipArchiveEntry
Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Jun 10, 2015 at 9:29 PM, Stefan Bodewig <bo...@apache.org> wrote:
> On 2015-06-10, Kristina Chodorow wrote:
>
> > ZipArchiveEntry.getExternalAttributes() is always returning 0 for me. I
> > have pasted a hex dump of the zip file I'm testing with at the bottom of
> > email: 2 files of 0 bytes, one named x and one named y. Both of their
> > external attributes are 33184 (a081 in the hex dump). However, running
> the
> > following program gives me 0 for both of their external attributes:
>
> External attributes are stored inside the central directory which is at
> the end of the archive. When using ZipArchiveInputStream the central
> directory is only ever reached once all entries have been read.
>
> If you need to access the information from the central directory you
> should use ZipFile rather than ZipArchiveInputStream.
>
Is that in the Javadoc?
Gary
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: [compress] Getting external attributes from a ZipArchiveEntry
Posted by Stefan Bodewig <bo...@apache.org>.
On 2015-06-10, Kristina Chodorow wrote:
> ZipArchiveEntry.getExternalAttributes() is always returning 0 for me. I
> have pasted a hex dump of the zip file I'm testing with at the bottom of
> email: 2 files of 0 bytes, one named x and one named y. Both of their
> external attributes are 33184 (a081 in the hex dump). However, running the
> following program gives me 0 for both of their external attributes:
External attributes are stored inside the central directory which is at
the end of the archive. When using ZipArchiveInputStream the central
directory is only ever reached once all entries have been read.
If you need to access the information from the central directory you
should use ZipFile rather than ZipArchiveInputStream.
Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org