Fix the EOF detection logic on Android

The current logic was causing loading to omit the last character because the EOF flag was triggered too early.
This commit is contained in:
Fredia Huya-Kouadio 2025-07-06 01:09:33 -07:00
parent 53be3b78d1
commit 2cfe31f9a1
2 changed files with 1 additions and 3 deletions

View file

@ -138,7 +138,6 @@ internal class AssetData(context: Context, private val filePath: String, accessF
0 0
} else { } else {
position += readBytes position += readBytes
endOfFile = position() >= size()
readBytes readBytes
} }
} catch (e: IOException) { } catch (e: IOException) {

View file

@ -216,7 +216,6 @@ internal abstract class DataAccess {
override fun seek(position: Long) { override fun seek(position: Long) {
try { try {
fileChannel.position(position) fileChannel.position(position)
endOfFile = position >= fileChannel.size()
} catch (e: Exception) { } catch (e: Exception) {
Log.w(TAG, "Exception when seeking file $filePath.", e) Log.w(TAG, "Exception when seeking file $filePath.", e)
} }
@ -260,8 +259,8 @@ internal abstract class DataAccess {
override fun read(buffer: ByteBuffer): Int { override fun read(buffer: ByteBuffer): Int {
return try { return try {
val readBytes = fileChannel.read(buffer) val readBytes = fileChannel.read(buffer)
endOfFile = readBytes == -1 || (fileChannel.position() >= fileChannel.size())
if (readBytes == -1) { if (readBytes == -1) {
endOfFile = true
0 0
} else { } else {
readBytes readBytes