diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2016-01-21 21:51:46 +0100 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2016-02-10 19:39:46 +0100 |
commit | 8a2152adf0f496f06bf626d0c97133d94a226b7a (patch) | |
tree | 2f8a0af0c8fead38eb5289217498104e7a7110a3 | |
parent | 075616c461f5ce2bd76a4078c31a51a6ee6b8605 (diff) | |
download | openpgp-api-8a2152adf0f496f06bf626d0c97133d94a226b7a.tar.gz openpgp-api-8a2152adf0f496f06bf626d0c97133d94a226b7a.tar.bz2 openpgp-api-8a2152adf0f496f06bf626d0c97133d94a226b7a.zip |
split executeApi method to allow self-supplied ParcelFileDescriptor input
-rw-r--r-- | openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java index 4ed36e6..3c0c837 100644 --- a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java +++ b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java @@ -310,11 +310,36 @@ public class OpenPgpApi { } } + public Intent executeApi(Intent data, InputStream is, OutputStream os) { + ParcelFileDescriptor input = null; + try { + if (is != null) { + input = ParcelFileDescriptorUtil.pipeFrom(is); + } + + return executeApi(data, input, os); + } catch (Exception e) { + Log.e(OpenPgpApi.TAG, "Exception in executeApi call", e); + Intent result = new Intent(); + result.putExtra(RESULT_CODE, RESULT_CODE_ERROR); + result.putExtra(RESULT_ERROR, + new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage())); + return result; + } finally { + if (input != null) { + try { + input.close(); + } catch (IOException e) { + Log.e(OpenPgpApi.TAG, "IOException when closing ParcelFileDescriptor!", e); + } + } + } + } + /** * InputStream and OutputStreams are always closed after operating on them! */ - public Intent executeApi(Intent data, InputStream is, OutputStream os) { - ParcelFileDescriptor input = null; + public Intent executeApi(Intent data, ParcelFileDescriptor input, OutputStream os) { ParcelFileDescriptor output = null; try { // always send version from client @@ -322,10 +347,6 @@ public class OpenPgpApi { Intent result; - if (is != null) { - input = ParcelFileDescriptorUtil.pipeFrom(is); - } - Thread pumpThread =null; int outputPipeId = 0; @@ -365,13 +386,6 @@ public class OpenPgpApi { Log.e(OpenPgpApi.TAG, "IOException when closing ParcelFileDescriptor!", e); } } - if (input != null) { - try { - input.close(); - } catch (IOException e) { - Log.e(OpenPgpApi.TAG, "IOException when closing ParcelFileDescriptor!", e); - } - } } } |