From ff1d943a6949edec6f87790a223ed1a71277bda5 Mon Sep 17 00:00:00 2001 From: Braden Shepherdson Date: Tue, 15 Jan 2013 13:21:09 -0500 Subject: [PATCH] Add CordovaArguments helper to decode ArrayBuffers --- .../src/org/apache/cordova/BinaryEcho.java | 6 +--- .../org/apache/cordova/CordovaArguments.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 framework/src/org/apache/cordova/CordovaArguments.java diff --git a/framework/src/org/apache/cordova/BinaryEcho.java b/framework/src/org/apache/cordova/BinaryEcho.java index ad7393fa..38ca9393 100644 --- a/framework/src/org/apache/cordova/BinaryEcho.java +++ b/framework/src/org/apache/cordova/BinaryEcho.java @@ -25,8 +25,6 @@ import org.apache.cordova.api.PluginResult; import org.json.JSONArray; import org.json.JSONException; -import android.util.Base64; - public class BinaryEcho extends CordovaPlugin { /** @@ -40,9 +38,7 @@ public class BinaryEcho extends CordovaPlugin { public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { try { if (action.equals("echo")) { - //CordovaJSONArray cdvArgs = (CordovaJSONArray) args; - //byte[] data = cdvArgs.getArrayBuffer(0); - byte[] data = Base64.decode(args.getString(0), Base64.DEFAULT); + byte[] data = CordovaArguments.getArrayBuffer(args, 0); // Don't return any result now, since status results will be sent when events come in from broadcast receiver PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, data); diff --git a/framework/src/org/apache/cordova/CordovaArguments.java b/framework/src/org/apache/cordova/CordovaArguments.java new file mode 100644 index 00000000..347dc5e8 --- /dev/null +++ b/framework/src/org/apache/cordova/CordovaArguments.java @@ -0,0 +1,36 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ +package org.apache.cordova; + +import org.json.JSONArray; +import org.json.JSONException; + +import android.util.Base64; +import android.util.Log; + +public class CordovaArguments { + public static byte[] getArrayBuffer(JSONArray args, int index) throws JSONException { + Log.i("Braden", "getting array buffer at index " + index); + String encoded = args.getString(index); + Log.i("Braden", encoded); + return Base64.decode(encoded, Base64.DEFAULT); + } +} + +