Minor cleanup

This commit is contained in:
Jobobby04 2024-05-04 23:15:17 -04:00
parent b6b33e8c00
commit 253060a3bc
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) {
ZipFile(channel)
ZipFile.Builder()
.setSeekableByteChannel(channel)
.get()
} else {
null
}

View File

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

View File

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