Decodes BASE64 encoded byte array.
(byte[] arr)
| 138 | * Decodes BASE64 encoded byte array. |
| 139 | */ |
| 140 | public final static byte[] decode(byte[] arr) { |
| 141 | int length = arr.length; |
| 142 | if (length == 0) { |
| 143 | return new byte[0]; |
| 144 | } |
| 145 | |
| 146 | int sndx = 0, endx = length - 1; |
| 147 | int pad = arr[endx] == '=' ? (arr[endx - 1] == '=' ? 2 : 1) : 0; |
| 148 | int cnt = endx - sndx + 1; |
| 149 | int sepCnt = length > 76 ? (arr[76] == '\r' ? cnt / 78 : 0) << 1 : 0; |
| 150 | int len = ((cnt - sepCnt) * 6 >> 3) - pad; |
| 151 | byte[] dest = new byte[len]; |
| 152 | |
| 153 | int d = 0; |
| 154 | for (int cc = 0, eLen = (len / 3) * 3; d < eLen; ) { |
| 155 | int i = INV[arr[sndx++]] << 18 | INV[arr[sndx++]] << 12 | INV[arr[sndx++]] << 6 | INV[arr[sndx++]]; |
| 156 | |
| 157 | dest[d++] = (byte) (i >> 16); |
| 158 | dest[d++] = (byte) (i >> 8); |
| 159 | dest[d++] = (byte) i; |
| 160 | |
| 161 | if (sepCnt > 0 && ++cc == 19) { |
| 162 | sndx += 2; |
| 163 | cc = 0; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | if (d < len) { |
| 168 | int i = 0; |
| 169 | for (int j = 0; sndx <= endx - pad; j++) { |
| 170 | i |= INV[arr[sndx++]] << (18 - j * 6); |
| 171 | } |
| 172 | for (int r = 16; d < len; r -= 8) { |
| 173 | dest[d++] = (byte) (i >> r); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | return dest; |
| 178 | } |
| 179 | |
| 180 | public final static String encodeToString(String s) { |
| 181 | try { |
no outgoing calls
no test coverage detected