[ 
https://issues.apache.org/jira/browse/COMPRESS-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17074349#comment-17074349
 ] 

Peter Lee edited comment on COMPRESS-508 at 4/3/20, 7:51 AM:
-------------------------------------------------------------

> 1. Get the metadata of the zip file : all entries , with their names and 
> sizes, and extra stuff that are considered important (I'm not familiar with 
> them).

We already have the ability to do it now. This could be achieved by ZipArchive 
like this:
{code:java}
File f = new File("D:\\temp\\20200401\\test.zip");
InputStream fileInputStream = new FileInputStream(f);
try (ZipArchiveInputStream inputStream = new 
ZipArchiveInputStream(fileInputStream, ZipEncodingHelper.UTF8, true, true)) {
    ArchiveEntry entry = inputStream.getNextEntry();
    System.out.println("name : " + entry.getName() + " , size : " + 
entry.getSize());

    // please note that I'm going to the next entry, then I can read the data 
descriptor of last entry
    inputStream.getNextEntry();
    System.out.println("name : " + entry.getName() + " , size : " + 
entry.getSize());

}
{code}
The output looks like this:

name : icon.png , size : -1
 name : icon.png , size : 702795

 

You can see the size is not -1 after I called inputStream.getNextEntry(). In 
this way, I can get all entries of the zip file. I think this is what you are 
talking about. ;)

 

> 2. Being able, for each entry, to get an inputStream from it

If you are not caching the whole data of the zip file beforehand ,this may be a 
little difficult when using input streams, as it doesn't support random access. 
I need to skip all the stuff to get input stream of some specific entry. 
Actually this is a little like 7zip(it's more complicated than zip). Doable but 
time consuming.

 

Update:

Ah, didn't refresh the thread when I was editing my reply. Seems you have 
already got your answer. [~AndroidDeveloperLB] . And the history part is really 
interesting [~bodewig] :)


was (Author: peterlee):
> 1. Get the metadata of the zip file : all entries , with their names and 
> sizes, and extra stuff that are considered important (I'm not familiar with 
> them).

We already have the ability to do it now. This could be achieved by ZipArchive 
like this:
{code:java}
File f = new File("D:\\temp\\20200401\\test.zip");
InputStream fileInputStream = new FileInputStream(f);
try (ZipArchiveInputStream inputStream = new 
ZipArchiveInputStream(fileInputStream, ZipEncodingHelper.UTF8, true, true)) {
    ArchiveEntry entry = inputStream.getNextEntry();
    System.out.println("name : " + entry.getName() + " , size : " + 
entry.getSize());

    // please note that I'm going to the next entry, then I can read the data 
descriptor of last entry
    inputStream.getNextEntry();
    System.out.println("name : " + entry.getName() + " , size : " + 
entry.getSize());

}
{code}
The output looks like this:

name : icon.png , size : -1
name : icon.png , size : 702795

 

You can see the size is not -1 after I called inputStream.getNextEntry(). In 
this way, I can get all entries of the zip file. I think this is what you are 
talking about. ;)

 

> 2. Being able, for each entry, to get an inputStream from it

If you are not caching the whole data of the zip file beforehand ,this may be a 
little difficult when using input streams, as it doesn't support random access. 
I need to skip all the stuff to get input stream of some specific entry. 
Actually this is a little like 7zip(it's more complicated than zip). Doable but 
time consuming.

> 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, 2020-04-01_18-28-19.mp4, 
> ZipTest.zip, ZipTest2.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.
> Files:
> !2020-03-31_20-53-36.png![^test.zip]
> [^ZipTest.zip]
> 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)

Reply via email to