Minor cleanup
This commit is contained in:
parent
b6b33e8c00
commit
253060a3bc
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
@ -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 <--
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user