diff --git a/core/src/main/java/de/raphaelebner/roomdatabasebackup/core/RoomBackup.kt b/core/src/main/java/de/raphaelebner/roomdatabasebackup/core/RoomBackup.kt index a908245..12d1775 100644 --- a/core/src/main/java/de/raphaelebner/roomdatabasebackup/core/RoomBackup.kt +++ b/core/src/main/java/de/raphaelebner/roomdatabasebackup/core/RoomBackup.kt @@ -417,13 +417,19 @@ class RoomBackup(var context: Context) { // Close the database roomDatabase!!.close() roomDatabase = null + + val bos = BufferedOutputStream(destination) if (backupIsEncrypted) { val encryptedBytes = encryptBackup() ?: return - destination.write(encryptedBytes) + bos.write(encryptedBytes) } else { // Copy current database to save location (/files dir) - copy(DATABASE_FILE, destination) + val inputStream = DATABASE_FILE.inputStream().buffered() + inputStream.copyTo(bos) + inputStream.close() } + bos.flush() + bos.close() // If maxFileCount is set and is reached, delete oldest file if (maxFileCount != null) {