public byte[] decode(String input) {
    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      StringReader in = new StringReader(input);
      for (int i = 0; i < input.length(); i += 4) {
        int a[] = {mapCharToInt(in), mapCharToInt(in), mapCharToInt(in), mapCharToInt(in)};
        int oneBigNumber =
            (a[0] & 0x3f) << 18 | (a[1] & 0x3f) << 12 | (a[2] & 0x3f) << 6 | (a[3] & 0x3f);
        for (int j = 0; j < 3; j++)
          if (a[j + 1] >= 0) out.write(0xff & oneBigNumber >> 8 * (2 - j));
      }
      return out.toByteArray();
    } catch (IOException e) {
      throw new Error(e + ": " + e.getMessage());
    }
  }
Encodes binary data to plain text as Base64.

<p>
Despite there being a gazillion other Base64 implementations out there, this has been written as
part of XStream as it forms a core part but is too trivial to warrant an extra dependency.
</p>

<p>
This meets the standard as described in RFC 1521, section 5.2
<http://www.freesoft.org/CIE/RFC/1521/7.htm>, allowing other Base64 tools to manipulate the data.
</p>

Original code from <a href="http://xstream.codehaus.org/">XStream</a>
selendroid-server/src/main/java/io/selendroid/server/android/internal/Base64Encoder.java