Search in sources :

Example 1 with PwDbOutput

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;
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) SyncFailedException(java.io.SyncFailedException) IOException(java.io.IOException) File(java.io.File) PwDbOutput(com.keepassdroid.database.save.PwDbOutput) InvalidDBException(com.keepassdroid.database.exception.InvalidDBException) PwDbOutputException(com.keepassdroid.database.exception.PwDbOutputException) InvalidPasswordException(com.keepassdroid.database.exception.InvalidPasswordException) ContentFileNotFoundException(com.keepassdroid.database.exception.ContentFileNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SyncFailedException(java.io.SyncFailedException)

Aggregations

ContentFileNotFoundException (com.keepassdroid.database.exception.ContentFileNotFoundException)1 InvalidDBException (com.keepassdroid.database.exception.InvalidDBException)1 InvalidPasswordException (com.keepassdroid.database.exception.InvalidPasswordException)1 PwDbOutputException (com.keepassdroid.database.exception.PwDbOutputException)1 PwDbOutput (com.keepassdroid.database.save.PwDbOutput)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 SyncFailedException (java.io.SyncFailedException)1