Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jobobby04 committed May 5, 2024
1 parent b6b33e8 commit 253060a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/exh/eh/MemAutoFlushingLookupTable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <--

Expand Down

0 comments on commit 253060a

Please sign in to comment.