aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-11-02 17:50:38 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-11-02 17:50:38 +0100
commit602930d92981e4fcf7a57fe2a6c4d32ec3f6bad8 (patch)
treef962977139c3717a302a87a0394623e8aa3da97e /OpenKeychain
parent9dc8c0d506703062b3c1b90042441b52689628d7 (diff)
parent1886dd1790536e07a0c2e6eac3006e93cb5611e1 (diff)
downloadopen-keychain-602930d92981e4fcf7a57fe2a6c4d32ec3f6bad8.tar.gz
open-keychain-602930d92981e4fcf7a57fe2a6c4d32ec3f6bad8.tar.bz2
open-keychain-602930d92981e4fcf7a57fe2a6c4d32ec3f6bad8.zip
Merge branch 'development' of github.com:open-keychain/open-keychain into development
Diffstat (limited to 'OpenKeychain')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java57
1 files changed, 39 insertions, 18 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java
index 9db9e700f..da532d2dc 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java
@@ -456,32 +456,53 @@ public class ImportExportOperation extends BaseOperation {
// For each public masterKey id
while (!cursor.isAfterLast()) {
- // Create an output stream
- ArmoredOutputStream arOutStream = new ArmoredOutputStream(outStream);
- String version = PgpHelper.getVersionForHeader(mContext);
- if (version != null) {
- arOutStream.setHeader("Version", version);
- }
-
long keyId = cursor.getLong(0);
+ ArmoredOutputStream arOutStream = null;
+
+ // Create an output stream
+ try {
+ arOutStream = new ArmoredOutputStream(outStream);
+ String version = PgpHelper.getVersionForHeader(mContext);
+ if (version != null) {
+ arOutStream.setHeader("Version", version);
+ }
- log.add(LogType.MSG_EXPORT_PUBLIC, 1, KeyFormattingUtils.beautifyKeyId(keyId));
+ log.add(LogType.MSG_EXPORT_PUBLIC, 1, KeyFormattingUtils.beautifyKeyId(keyId));
- { // export public key part
- byte[] data = cursor.getBlob(1);
- arOutStream.write(data);
- arOutStream.close();
+ { // export public key part
+ byte[] data = cursor.getBlob(1);
+ arOutStream.write(data);
- okPublic += 1;
+ okPublic += 1;
+ }
+ } finally {
+ // make sure this is closed
+ if (arOutStream != null) {
+ arOutStream.close();
+ }
+ arOutStream = null;
}
- // export secret key part
if (exportSecret && cursor.getInt(3) > 0) {
- log.add(LogType.MSG_EXPORT_SECRET, 2, KeyFormattingUtils.beautifyKeyId(keyId));
- byte[] data = cursor.getBlob(2);
- arOutStream.write(data);
+ try {
+ arOutStream = new ArmoredOutputStream(outStream);
+ String version = PgpHelper.getVersionForHeader(mContext);
+ if (version != null) {
+ arOutStream.setHeader("Version", version);
+ }
- okSecret += 1;
+ // export secret key part
+ log.add(LogType.MSG_EXPORT_SECRET, 2, KeyFormattingUtils.beautifyKeyId(keyId));
+ byte[] data = cursor.getBlob(2);
+ arOutStream.write(data);
+
+ okSecret += 1;
+ } finally {
+ // make sure this is closed
+ if (arOutStream != null) {
+ arOutStream.close();
+ }
+ }
}
updateProgress(progress++, numKeys);