Minor cleanup

(cherry picked from commit 253060a3bcc7f70f409944ec5212d3e2cd4542f8)
This commit is contained in:
Jobobby04 2024-05-04 23:15:17 -04:00 committed by Cuong Tran
parent 4465aae0fd
commit 28d9778d49
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
3 changed files with 12 additions and 7 deletions

View file

@ -43,7 +43,9 @@ internal class ZipPageLoader(file: UniFile, context: Context) : PageLoader() {
} }
private val apacheZip: ZipFile? = if (!file.isEncryptedZip() && Build.VERSION.SDK_INT > Build.VERSION_CODES.N) { private val apacheZip: ZipFile? = if (!file.isEncryptedZip() && Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
ZipFile(channel) ZipFile.Builder()
.setSeekableByteChannel(channel)
.get()
} else { } else {
null null
} }

View file

@ -17,10 +17,13 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import okio.BufferedSource
import okio.buffer
import okio.sink
import okio.source
import java.io.Closeable import java.io.Closeable
import java.io.File import java.io.File
import java.io.FileNotFoundException import java.io.FileNotFoundException
import java.io.InputStream
import java.nio.ByteBuffer import java.nio.ByteBuffer
import kotlin.concurrent.thread import kotlin.concurrent.thread
@ -67,7 +70,7 @@ class MemAutoFlushingLookupTable<T>(
Runtime.getRuntime().addShutdownHook(shutdownHook) Runtime.getRuntime().addShutdownHook(shutdownHook)
} }
private fun InputStream.requireBytes(targetArray: ByteArray, byteCount: Int): Boolean { private fun BufferedSource.requireBytes(targetArray: ByteArray, byteCount: Int): Boolean {
var readIter = 0 var readIter = 0
while (true) { while (true) {
val readThisIter = read(targetArray, readIter, byteCount - readIter) val readThisIter = read(targetArray, readIter, byteCount - readIter)
@ -80,7 +83,7 @@ class MemAutoFlushingLookupTable<T>(
private fun initialLoad() { private fun initialLoad() {
launch { launch {
try { try {
atomicFile.openRead().buffered().use { input -> atomicFile.openRead().source().buffer().use { input ->
val bb = ByteBuffer.allocate(8) val bb = ByteBuffer.allocate(8)
while (true) { while (true) {
@ -126,7 +129,7 @@ class MemAutoFlushingLookupTable<T>(
val fos = atomicFile.startWrite() val fos = atomicFile.startWrite()
try { try {
val out = fos.buffered() val out = fos.sink().buffer()
table.forEach { key, value -> table.forEach { key, value ->
val v = serializer.write(value).toByteArray(Charsets.UTF_8) val v = serializer.write(value).toByteArray(Charsets.UTF_8)
bb.putInt(0, key) bb.putInt(0, key)

View file

@ -26,9 +26,9 @@ class EpubFile(file: UniFile, context: Context) : Closeable {
* Zip file of this epub. * Zip file of this epub.
*/ */
private val zip = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { private val zip = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
ZipFile(tempFileManager.createTempFile(file)) ZipFile.Builder().setFile(tempFileManager.createTempFile(file)).get()
} else { } else {
ZipFile(file.openReadOnlyChannel(context)) ZipFile.Builder().setSeekableByteChannel(file.openReadOnlyChannel(context)).get()
} }
// SY <-- // SY <--