fix(source/local): Crash when trying to read EPUB file

FileInputStream have a safeguard that prevent it from being closed twice, ArchiveInputStream doesn't have that.

Fixes GH-115

REF:
- Jsoup parse javadoc: "in: InputStream – input stream to read. The stream will be closed after reading"
This commit is contained in:
Ahmad Ansori Palembani 2024-06-30 10:08:49 +07:00
parent 7404712e9c
commit 3b60b0069b
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -4,8 +4,13 @@ import me.zhanghai.android.libarchive.Archive
import me.zhanghai.android.libarchive.ArchiveEntry
import me.zhanghai.android.libarchive.ArchiveException
import java.nio.ByteBuffer
import kotlin.concurrent.Volatile
class AndroidArchiveInputStream(buffer: Long, size: Long) : ArchiveInputStream() {
private val lock = Any()
@Volatile
private var isClosed = false
private val archive = Archive.readNew()
init {
@ -40,6 +45,11 @@ class AndroidArchiveInputStream(buffer: Long, size: Long) : ArchiveInputStream()
}
override fun close() {
synchronized(lock) {
if (isClosed) return
isClosed = true
}
Archive.readFree(archive)
}