Java Utililty Methods Base64

List of utility methods to do Base64

Description

The list of methods to do Base64 are organized into topic(s).

Method

Stringbase64()
base
String systemName = systemName();
String ret;
if ("Linux".equals(systemName)) {
    ret = "base64 -w";
} else if ("Mac OS X".equals(systemName)) {
    ret = "base64 -b";
} else {
    throw new RuntimeException(String.format("%s is not a supported platform.", systemName));
...
Stringbase64(byte[] buf)
Base-64 encode a byte array, returning the returning string.
int bitOffset, byteOffset, index = 0;
int bytes = (buf.length * 8 + 5) / 6;
StringBuilder out = new StringBuilder(bytes);
for (int i = 0; i < bytes; i++) {
    byteOffset = (i * 6) / 8;
    bitOffset = (i * 6) % 8;
    if (bitOffset < 3) {
        index = (buf[byteOffset] >>> (2 - bitOffset)) & 0x3f;
...
Stringbase64(byte[] buff)
base
return new String(Base64.getEncoder().encode(buff));
Stringbase64(byte[] data)
Base64 encode the input data.
Base64.Encoder b64enc = Base64.getMimeEncoder(LINE_LENGTH, LINE_SEP);
return b64enc.encodeToString(data);
Stringbase64(byte[] raw)
base
int ixtext, lentext;
int ctremaining;
byte[] input = new byte[3], output = new byte[4];
short i, charsonline = 0, ctcopy;
StringBuffer result;
lentext = raw.length;
if (lentext < 1) {
    return "";
...
Stringbase64(final byte[] stringArray)
base
final StringBuilder encoded = new StringBuilder();
final int paddingCount = (3 - (stringArray.length % 3)) % 3;
final byte[] paddedArray = zeroPad(stringArray.length + paddingCount, stringArray);
for (int i = 0; i < paddedArray.length; i += 3) {
    final int j = ((paddedArray[i] & 0xff) << 16) + ((paddedArray[i + 1] & 0xff) << 8)
            + (paddedArray[i + 2] & 0xff);
    encoded.append(BASE64ALPHA.charAt((j >> 18) & 0x3f));
    encoded.append(BASE64ALPHA.charAt((j >> 12) & 0x3f));
...
StringBase64(String msg)
Base
BASE64Decoder decoder = new BASE64Decoder();
byte[] byteData = null;
String clearText = "";
try {
    byteData = decoder.decodeBuffer(msg);
    clearText = new String(byteData);
} catch (IOException e) {
    e.printStackTrace();
...
Stringbase64(String string)
base
try {
    return Base64.getMimeEncoder().encodeToString(string.getBytes("ISO-8859-1"));
} catch (UnsupportedEncodingException e) {
    return "";
Stringbase64(String value)
Creates the Base64 value.
StringBuffer cb = new StringBuffer();
int i = 0;
for (i = 0; i + 2 < value.length(); i += 3) {
    long chunk = (int) value.charAt(i);
    chunk = (chunk << 8) + (int) value.charAt(i + 1);
    chunk = (chunk << 8) + (int) value.charAt(i + 2);
    cb.append(encode(chunk >> 18));
    cb.append(encode(chunk >> 12));
...
booleanbase64Append(StringBuilder sb, int digit, boolean haveNonZero)
base Append
if (digit > 0) {
    haveNonZero = true;
if (haveNonZero) {
    sb.append(base64Chars[digit]);
return haveNonZero;