| 21 | import java.util.*; |
| 22 | |
| 23 | public class LZString { |
| 24 | |
| 25 | private static final char[] keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray(); |
| 26 | private static final char[] keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$".toCharArray(); |
| 27 | private static final Map<char[], Map<Character, Integer>> baseReverseDic = new HashMap<char[], Map<Character, Integer>>(); |
| 28 | |
| 29 | private static char getBaseValue(char[] alphabet, Character character) { |
| 30 | Map<Character, Integer> map = baseReverseDic.get(alphabet); |
| 31 | if (map == null) { |
| 32 | map = new HashMap<Character, Integer>(); |
| 33 | baseReverseDic.put(alphabet, map); |
| 34 | for (int i = 0; i < alphabet.length; i++) { |
| 35 | map.put(alphabet[i], i); |
| 36 | } |
| 37 | } |
| 38 | return (char) map.get(character).intValue(); |
| 39 | } |
| 40 | |
| 41 | public static String compressToBase64(String input) { |
| 42 | if (input == null) |
| 43 | return ""; |
| 44 | String res = LZString._compress(input, 6, new CompressFunctionWrapper() { |
| 45 | @Override |
| 46 | public char doFunc(int a) { |
| 47 | return keyStrBase64[a]; |
| 48 | } |
| 49 | }); |
| 50 | switch (res.length() % 4) { // To produce valid Base64 |
| 51 | default: // When could this happen ? |
| 52 | case 0: |
| 53 | return res; |
| 54 | case 1: |
| 55 | return res + "==="; |
| 56 | case 2: |
| 57 | return res + "=="; |
| 58 | case 3: |
| 59 | return res + "="; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | public static String decompressFromBase64(final String inputStr) { |
| 64 | if (inputStr == null) |
| 65 | return ""; |
| 66 | if (inputStr.equals("")) |
| 67 | return null; |
| 68 | return LZString._decompress(inputStr.length(), 32, new DecompressFunctionWrapper() { |
| 69 | @Override |
| 70 | public char doFunc(int index) { |
| 71 | return getBaseValue(keyStrBase64, inputStr.charAt(index)); |
| 72 | } |
| 73 | }); |
| 74 | } |
| 75 | |
| 76 | public static String compressToUTF16(String input) { |
| 77 | if (input == null) |
| 78 | return ""; |
| 79 | return LZString._compress(input, 15, new CompressFunctionWrapper() { |
| 80 | @Override |
nothing calls this directly
no test coverage detected