use of com.keepassdroid.database.save.PwDbOutput in project KeePassDX by Kunzisoft.
the class Database method SaveData.
public void SaveData(Context ctx, Uri uri) throws IOException, PwDbOutputException {
if (uri.getScheme().equals("file")) {
String filename = uri.getPath();
File tempFile = new File(filename + ".tmp");
FileOutputStream fos = new FileOutputStream(tempFile);
// BufferedOutputStream bos = new BufferedOutputStream(fos);
// PwDbV3Output pmo = new PwDbV3Output(pm, bos, App.getCalendar());
PwDbOutput pmo = PwDbOutput.getInstance(pm, fos);
pmo.output();
// bos.flush();
// bos.close();
fos.close();
// Force data to disk before continuing
try {
fos.getFD().sync();
} catch (SyncFailedException e) {
// Ignore if fsync fails. We tried.
}
File orig = new File(filename);
if (!tempFile.renameTo(orig)) {
throw new IOException("Failed to store database.");
}
} else {
OutputStream os;
try {
os = ctx.getContentResolver().openOutputStream(uri);
} catch (Exception e) {
throw new IOException("Failed to store database.");
}
PwDbOutput pmo = PwDbOutput.getInstance(pm, os);
pmo.output();
os.close();
}
mUri = uri;
}
Aggregations