From 8a2152adf0f496f06bf626d0c97133d94a226b7a Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 21 Jan 2016 21:51:46 +0100 Subject: split executeApi method to allow self-supplied ParcelFileDescriptor input --- .../org/openintents/openpgp/util/OpenPgpApi.java | 40 +++++++++++++++------- 1 file 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); - } - } } } -- cgit v1.2.3