[
https://issues.apache.org/jira/browse/COMPRESS-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17074494#comment-17074494
]
AD_LB commented on COMPRESS-508:
--------------------------------
[~bodewig]
I see.
Does it take memory in the heap, or in JNI "world" ?
On Android (and I think on PC too), it's important, because the heap can be
quite limited compared to the entire device's RAM.
A device could have 8 GB of RAM, but much less than that for heap.
Also, for heap handling we get OOM exception, but for JNI the behavior could be
unpredictable (silent crash, weird exception, ...).
Maybe I should check it out myself. Things change on Android on memory-related
stuff sometimes.
As for the code, why do you call "close" on "bos" ? It says it doesn't do
anything:
"Closing a ByteArrayOutputStream has no effect. The methods in this class can
be called after the stream has been closed without generating an IOException."
Anyway, I tested it now. Seems to work well:
{code:kt}
ByteArrayOutputStream().use { byteArrayOutputStream ->
FileInputStream(file).copyTo(byteArrayOutputStream)
ZipFile(SeekableInMemoryByteChannel(byteArrayOutputStream.toByteArray())).use {
for (entry in it.entries) {
Log.d("AppLog", "entry:${entry.name} ${entry.size}
")
}
}
}
{code}
All I have to do now is to replace "copyTo" to something that's limited via a
parameter (max memory to use), and I think this is a nice solution.
Is that what you mean by "If you want to stop reading big archives, don't use
"our" copy method." ?
> 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, ZipTest3.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)