aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2015-01-29 11:17:16 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2015-01-29 11:17:16 +0100
commita5a3e2b3014cba2f1a7d356731fc3e3d066c6c62 (patch)
treec34cb31b1acf5fd732e8fb19ef6cf63d8e80354b
parentee2eb274a42a05518f2bc26fa8af816dde271d63 (diff)
downloadopenpgp-api-a5a3e2b3014cba2f1a7d356731fc3e3d066c6c62.tar.gz
openpgp-api-a5a3e2b3014cba2f1a7d356731fc3e3d066c6c62.tar.bz2
openpgp-api-a5a3e2b3014cba2f1a7d356731fc3e3d066c6c62.zip
Close output ParcelFileDescriptor in finally clause
-rw-r--r--src/org/openintents/openpgp/util/OpenPgpApi.java21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/org/openintents/openpgp/util/OpenPgpApi.java b/src/org/openintents/openpgp/util/OpenPgpApi.java
index 589b514..9f51851 100644
--- a/src/org/openintents/openpgp/util/OpenPgpApi.java
+++ b/src/org/openintents/openpgp/util/OpenPgpApi.java
@@ -27,6 +27,7 @@ import android.util.Log;
import org.openintents.openpgp.IOpenPgpService;
import org.openintents.openpgp.OpenPgpError;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -291,13 +292,15 @@ public class OpenPgpApi {
}
public Intent executeApi(Intent data, InputStream is, OutputStream os) {
+ ParcelFileDescriptor input = null;
+ ParcelFileDescriptor output = null;
try {
+ // always send version from client
data.putExtra(EXTRA_API_VERSION, OpenPgpApi.API_VERSION);
Intent result;
// pipe the input and output
- ParcelFileDescriptor input = null;
if (is != null) {
input = ParcelFileDescriptorUtil.pipeFrom(is,
new ParcelFileDescriptorUtil.IThreadListener() {
@@ -309,7 +312,6 @@ public class OpenPgpApi {
}
);
}
- ParcelFileDescriptor output = null;
if (os != null) {
output = ParcelFileDescriptorUtil.pipeTo(os,
new ParcelFileDescriptorUtil.IThreadListener() {
@@ -324,11 +326,6 @@ public class OpenPgpApi {
// blocks until result is ready
result = mService.execute(data, input, output);
- // close() is required to halt the TransferThread
- if (output != null) {
- output.close();
- }
- // TODO: close input?
// set class loader to current context to allow unparcelling
// of OpenPgpError and OpenPgpSignatureResult
@@ -343,6 +340,16 @@ public class OpenPgpApi {
result.putExtra(RESULT_ERROR,
new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
return result;
+ } finally {
+ // close() is required to halt the TransferThread
+ if (output != null) {
+ try {
+ output.close();
+ } catch (IOException e) {
+ Log.e(OpenPgpApi.TAG, "IOException when closing ParcelFileDescriptor!", e);
+ }
+ }
+ // TODO: close input? Maybe the client wants to still use the input stream
}
}