code: public static char[] encode(byte[] src, char[] table, char pad) {
          int len = src.length;
  
          if (len == 0) return new char[0];
  
          int blocks = (len / 3) * 3;
          int chars  = ((len - 1) / 3 + 1) << 2;
          int tail   = len - blocks;
          if (pad == 0 && tail > 0) chars -= 3 - tail;
  
          char[] dst = new char[chars];
          int si = 0, di = 0;
  
          while (si < blocks) {
              int n = (src[si++] & 0xff) << 16 | (src[si++] & 0xff) << 8 | (src[si++] & 0xff);
              dst[di++] = table[(n >>> 18) & 0x3f];
              dst[di++] = table[(n >>> 12) & 0x3f];
              dst[di++] = table[(n >>>  6) & 0x3f];
              dst[di++] = table[n          & 0x3f];
          }
  
          if (tail > 0) {
              int n = (src[si] & 0xff) << 10;
              if (tail == 2) n |= (src[++si] & 0xff) << 2;
  
              dst[di++] = table[(n >>> 12) & 0x3f];
              dst[di++] = table[(n >>> 6)  & 0x3f];
              if (tail == 2) dst[di++] = table[n & 0x3f];
  
              if (pad != 0) {
                  if (tail == 1) dst[di++] = pad;
                  dst[di] = pad;
              }
          }
  
          return dst;
      }
docs: Encode bytes to base64 chars using the supplied encode table and with
  optional padding.
  
  @param src   Bytes to encode.
  @param table Encoding table.
  @param pad   Padding character, or 0 for no padding.
  
  @return Encoded chars.