[FileAccess] Return error codes from store_* methods.

This commit is contained in:
bruvzg 2023-06-15 21:21:43 +03:00 committed by Pāvels Nadtočajevs
parent 56a7dba10b
commit a4b17e7852
30 changed files with 279 additions and 138 deletions

View file

@ -145,7 +145,8 @@ internal class AssetData(context: Context, private val filePath: String, accessF
}
}
override fun write(buffer: ByteBuffer) {
override fun write(buffer: ByteBuffer): Boolean {
Log.w(TAG, "write() is not supported.")
return false
}
}

View file

@ -169,7 +169,7 @@ internal abstract class DataAccess {
abstract fun position(): Long
abstract fun size(): Long
abstract fun read(buffer: ByteBuffer): Int
abstract fun write(buffer: ByteBuffer)
abstract fun write(buffer: ByteBuffer): Boolean
fun seekFromEnd(positionFromEnd: Long) {
val positionFromBeginning = max(0, size() - positionFromEnd)
@ -254,14 +254,16 @@ internal abstract class DataAccess {
}
}
override fun write(buffer: ByteBuffer) {
override fun write(buffer: ByteBuffer): Boolean {
try {
val writtenBytes = fileChannel.write(buffer)
if (writtenBytes > 0) {
endOfFile = false
}
return true
} catch (e: IOException) {
Log.w(TAG, "Exception while writing to file $filePath.", e)
return false
}
}
}

View file

@ -191,12 +191,12 @@ class FileAccessHandler(val context: Context) {
return files[fileId].read(byteBuffer)
}
fun fileWrite(fileId: Int, byteBuffer: ByteBuffer?) {
fun fileWrite(fileId: Int, byteBuffer: ByteBuffer?): Boolean {
if (!hasFileId(fileId) || byteBuffer == null) {
return
return false
}
files[fileId].write(byteBuffer)
return files[fileId].write(byteBuffer)
}
fun fileFlush(fileId: Int) {