aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2015-09-28 04:20:33 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2015-09-28 04:20:33 +0200
commit5f1259f3f7423646f0c4cd0b611746936b01b8b1 (patch)
treea6e81c9d4e0adb3a6946544f3b988545ed10027e /OpenKeychain/src/main/java/org
parent46e24058ba02b5302553c031d301484d5cbf2d18 (diff)
downloadopen-keychain-5f1259f3f7423646f0c4cd0b611746936b01b8b1.tar.gz
open-keychain-5f1259f3f7423646f0c4cd0b611746936b01b8b1.tar.bz2
open-keychain-5f1259f3f7423646f0c4cd0b611746936b01b8b1.zip
export: improve stream handling, performance
Diffstat (limited to 'OpenKeychain/src/main/java/org')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ExportOperation.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ExportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ExportOperation.java
index 3ee5ff771..ecff9f5ae 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ExportOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ExportOperation.java
@@ -19,6 +19,8 @@
package org.sufficientlysecure.keychain.operations;
+import java.io.BufferedOutputStream;
+import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -111,12 +113,18 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
? exportInput.mOutputUri
: TemporaryStorageProvider.createFile(mContext);
+ int exportedDataSize;
+
{ // export key data, and possibly return if we don't encrypt
- OutputStream outStream = mContext.getContentResolver().openOutputStream(exportOutputUri);
+ DataOutputStream outStream = new DataOutputStream(new BufferedOutputStream(
+ mContext.getContentResolver().openOutputStream(exportOutputUri)));
+
boolean exportSuccess = exportKeysToStream(
log, exportInput.mMasterKeyIds, exportInput.mExportSecret, outStream);
+ exportedDataSize = outStream.size();
+
if (!exportSuccess) {
// if there was an error, it will be in the log so we just have to return
return new ExportResult(ExportResult.RESULT_ERROR, log);
@@ -138,7 +146,7 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
InputStream inStream = mContext.getContentResolver().openInputStream(exportOutputUri);
String filename;
- if (exportInput.mMasterKeyIds.length == 1) {
+ if (exportInput.mMasterKeyIds != null && exportInput.mMasterKeyIds.length == 1) {
filename = "backup_" + KeyFormattingUtils.convertKeyIdToHex(exportInput.mMasterKeyIds[0]);
filename += exportInput.mExportSecret ? ".sec.asc" : ".pub.asc";
} else {
@@ -146,9 +154,10 @@ public class ExportOperation extends BaseOperation<ExportKeyringParcel> {
filename += exportInput.mExportSecret ? ".asc" : ".pub.asc";
}
- InputData inputData = new InputData(inStream, 0L, filename);
+ InputData inputData = new InputData(inStream, exportedDataSize, filename);
OutputStream outStream = mContext.getContentResolver().openOutputStream(exportInput.mOutputUri);
+ outStream = new BufferedOutputStream(outStream);
PgpSignEncryptResult encryptResult = pseOp.execute(inputParcel, new CryptoInputParcel(), inputData, outStream);
if (!encryptResult.success()) {