package uk.co.dbyz.cordova.leaflet.mbtiles;

import org.apache.cordova.*;
import org.apache.commons.codec.binary.*;
import org.apache.commons.codec.DecoderException;
import org.json.JSONArray;
import org.json.JSONException;

public class MBTiles extends CordovaPlugin {

    @Override
    public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {

        if (action.equals("hextob64")) {
            //convert String to char array (1st step)
            char[] charArray = data.getString(0).toCharArray();
            
			try {
				// decode the char array to byte[] (2nd step)
				byte[] decodedHex = Hex.decodeHex(charArray);

				// The String decoded to Base64 (3rd step)
				String result= Base64.encodeBase64String(decodedHex);
					
				callbackContext.success(result);
			}catch(DecoderException ex){
				callbackContext.error(ex.getMessage());
			}
            return true;

        } else {
            
            return false;

        }
    }
}

@@ -106,17 +106,66 @@
 .binary.
-*
+Hex;%0Aimport org.apache.commons.codec.binary.Base64
 ;%0Aimport
@@ -437,25 +437,27 @@
 Exception %7B%0A
+%09%09
 %0A
-
         if (
@@ -792,16 +792,27 @@
 result= 
+new String(
 Base64.e
@@ -822,22 +822,16 @@
 deBase64
-String
 (decoded
@@ -834,16 +834,17 @@
 odedHex)
+)
 ;%0A%09%09%09%09%09%0A

Call Fixes