You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Peter Lee (Jira)" <ji...@apache.org> on 2020/04/01 02:36:00 UTC
[jira] [Comment Edited] (COMPRESS-508) Bug: cannot get file size of
ArchiveEntry using ZipArchiveInputStream
[ https://issues.apache.org/jira/browse/COMPRESS-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17072314#comment-17072314 ]
Peter Lee edited comment on COMPRESS-508 at 4/1/20, 2:35 AM:
-------------------------------------------------------------
Tried with the test.zip. I found that there will be an exception when reading the entry *icon.png.*
I found that this file is using the STORED compression method, and the general purpose bit shows that this entry is using data descriptor.
In this case, you should set the *allowStoredEntriesWithDataDescriptor* as *true* with the constructor of ZipArchiveInputStream, which is false by default.
I can successfully go through all the entries in this zip using the following code(JAVA):
{code:java}
File f = new File("/home/test/test.zip");
InputStream fileInputStream = new FileInputStream(f);
try (ZipArchiveInputStream inputStream = new ZipArchiveInputStream(fileInputStream, ZipEncodingHelper.UTF8, true, true)) {
ArchiveEntry entry = inputStream.getNextEntry();
while(entry != null) {
entry = inputStream.getNextEntry();
entry = entry;
}
}
{code}
Please note that I'm using *new ZipArchiveInputStream(fileInputStream, ZipEncodingHelper.UTF8, true, true)*
I'm not familiar with kotlin. Maybe you can try it on yourself.
was (Author: peterlee):
Tried with the test.zip. I found that there will be an exception when reading the entry *icon.png.*
I found that this file is using the STORED compression method, and the general purpose bit shows that this entry is using data descriptor.
In this case, you should set the *allowStoredEntriesWithDataDescriptor* as *true* with the constructor of ZipArchiveInputStream, which is false by default.
I can successfully go through all the entries in this zip using the following code(JAVA):
{code:java}
// code placeholder
File f = new File("/home/test/test.zip");
InputStream fileInputStream = new FileInputStream(f);
try (ZipArchiveInputStream inputStream = new ZipArchiveInputStream(fileInputStream, ZipEncodingHelper.UTF8, true, true)) {
ArchiveEntry entry = inputStream.getNextEntry();
while(entry != null) {
entry = inputStream.getNextEntry();
entry = entry;
}
}
{code}
Please note that I'm using *new ZipArchiveInputStream(fileInputStream, ZipEncodingHelper.UTF8, true, true)*
I'm not familiar with kotlin. Maybe you can try it on yourself.
> Bug: cannot get file size of ArchiveEntry using ZipArchiveInputStream
> ---------------------------------------------------------------------
>
> Key: COMPRESS-508
> URL: https://issues.apache.org/jira/browse/COMPRESS-508
> Project: Commons Compress
> Issue Type: Bug
> Components: Build
> Affects Versions: 1.20
> Environment: Android 9 and Android 10, on both emulator and real device .
> Reporter: AD_LB
> Priority: Major
> Attachments: 2020-03-31_20-53-36.png, ZipTest.zip, test.zip
>
>
> I'm trying to use ZipArchiveInputStream to iterate over the items of a zip file (which may or may not be a real file on the file-system, which is why I use a stream), optionally creating a stream from specific entries.
> One of the operations I need is to get the size of the files within.
> For some reason, it fails to do so. Not only that, but it throws an exception when I'm done with it:
> {code:java}
> Error:org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException: Unsupported feature data descriptor used in entry ...
> {code}
> I've attached here 3 files:sample project, the problematic zip file (remember that you need to put it in the correct path and grant storage permission), and a screenshot of the issue.
> Note that if I open the file using a third party PC app (such as [7-zip|https://www.7-zip.org/] ), it works fine, including showing the file size inside.
> Here's the relevant code (kotlin) :
>
> {code:java}
> thread {
> try {
> val file = File("/storage/emulated/0/test.zip")
> ZipArchiveInputStream(FileInputStream(file)).use {
> while (true) {
> val entry = it.nextEntry ?: break
> Log.d("AppLog", "entry:${entry.name} ${entry.size} ")
> }
> }
> Log.d("AppLog", "got archive ")
> } catch (e: Exception) {
> Log.d("AppLog", "Error:$e")
> e.printStackTrace()
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)