Add comments to explain why openAndTruncateStream()
This commit is contained in:
parent
df941670a8
commit
b21981a9c7
2 changed files with 5 additions and 0 deletions
|
@ -76,6 +76,9 @@ public class SubscriptionsExportService extends BaseImportExportService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
outFile = new StoredFileHelper(this, path, "application/json");
|
outFile = new StoredFileHelper(this, path, "application/json");
|
||||||
|
// truncate the file before writing to it, otherwise if the new content is smaller than
|
||||||
|
// the previous file size, the file will retain part of the previous content and be
|
||||||
|
// corrupted
|
||||||
outputStream = new SharpOutputStream(outFile.openAndTruncateStream());
|
outputStream = new SharpOutputStream(outFile.openAndTruncateStream());
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
handleError(e);
|
handleError(e);
|
||||||
|
|
|
@ -24,6 +24,8 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) {
|
||||||
*/
|
*/
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun exportDatabase(preferences: SharedPreferences, file: StoredFileHelper) {
|
fun exportDatabase(preferences: SharedPreferences, file: StoredFileHelper) {
|
||||||
|
// truncate the file before writing to it, otherwise if the new content is smaller than the
|
||||||
|
// previous file size, the file will retain part of the previous content and be corrupted
|
||||||
ZipOutputStream(SharpOutputStream(file.openAndTruncateStream()).buffered()).use { outZip ->
|
ZipOutputStream(SharpOutputStream(file.openAndTruncateStream()).buffered()).use { outZip ->
|
||||||
// add the database
|
// add the database
|
||||||
ZipHelper.addFileToZip(
|
ZipHelper.addFileToZip(
|
||||||
|
|
Loading…
Reference in a new issue