mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-05 16:50:50 +08:00
24 lines
763 B
Kotlin
24 lines
763 B
Kotlin
package android.util
|
|
|
|
import java.io.File
|
|
import java.io.FileOutputStream
|
|
|
|
// Boundary double only; the actual journal serializes/validates its own state
|
|
// and performs real temporary-file writes, fsync and rename in these tests.
|
|
class AtomicFile(private val file: File) {
|
|
private val pending = File(file.path + ".new")
|
|
fun readFully(): ByteArray = file.readBytes()
|
|
fun startWrite(): FileOutputStream {
|
|
file.parentFile.mkdirs()
|
|
return FileOutputStream(pending)
|
|
}
|
|
fun finishWrite(stream: FileOutputStream) {
|
|
stream.close()
|
|
check(pending.renameTo(file))
|
|
}
|
|
fun failWrite(stream: FileOutputStream) { stream.close(); pending.delete() }
|
|
}
|
|
object Log {
|
|
fun w(tag: String, message: String): Int { println("[$tag] $message"); return 0 }
|
|
}
|