mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 02:34:39 +00:00
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:
parent
7404712e9c
commit
3b60b0069b
1 changed files with 10 additions and 0 deletions
|
@ -4,8 +4,13 @@ import me.zhanghai.android.libarchive.Archive
|
||||||
import me.zhanghai.android.libarchive.ArchiveEntry
|
import me.zhanghai.android.libarchive.ArchiveEntry
|
||||||
import me.zhanghai.android.libarchive.ArchiveException
|
import me.zhanghai.android.libarchive.ArchiveException
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
import kotlin.concurrent.Volatile
|
||||||
|
|
||||||
class AndroidArchiveInputStream(buffer: Long, size: Long) : ArchiveInputStream() {
|
class AndroidArchiveInputStream(buffer: Long, size: Long) : ArchiveInputStream() {
|
||||||
|
private val lock = Any()
|
||||||
|
@Volatile
|
||||||
|
private var isClosed = false
|
||||||
|
|
||||||
private val archive = Archive.readNew()
|
private val archive = Archive.readNew()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -40,6 +45,11 @@ class AndroidArchiveInputStream(buffer: Long, size: Long) : ArchiveInputStream()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
|
synchronized(lock) {
|
||||||
|
if (isClosed) return
|
||||||
|
isClosed = true
|
||||||
|
}
|
||||||
|
|
||||||
Archive.readFree(archive)
|
Archive.readFree(archive)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue