diff options
-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); - } - } } } |