if (ti < bt.length) { byte[] tmp = new byte[ti]; System.arraycopy(bt, 0, tmp, 0, ti); bt = tmp; }
  public static byte[] encode(byte[] bs)  {    int si = 0, ti = 0;         // source/target array indices    byte[] bt = new byte[((bs.length + 2) * 4) / 3];     // target byte array    for (; si < bs.length; si += 3)      {        int buflen = bs.length - si;        if (buflen == 1)          {            byte b = bs[si];            int i = 0;            bt[ti++] = src[b >>> 2 & 0x3f];            bt[ti++] = src[(b << 4 & 0x30) + (i >>> 4 & 0xf)];          }        else if (buflen == 2)          {            byte b1 = bs[si], b2 = bs[si + 1];            int i = 0;            bt[ti++] = src[b1 >>> 2 & 0x3f];            bt[ti++] = src[(b1 << 4 & 0x30) + (b2 >>> 4 & 0xf)];            bt[ti++] = src[(b2 << 2 & 0x3c) + (i >>> 6 & 0x3)];          }        else          {            byte b1 = bs[si], b2 = bs[si + 1], b3 = bs[si + 2];            bt[ti++] = src[b1 >>> 2 & 0x3f];            bt[ti++] = src[(b1 << 4 & 0x30) + (b2 >>> 4 & 0xf)];            bt[ti++] = src[(b2 << 2 & 0x3c) + (b3 >>> 6 & 0x3)];            bt[ti++] = src[b3 & 0x3f];          }      }    /*while (ti < bt.length)      {        bt[ti++] = 0x3d;      }*/    return bt;  }