Java Utililty Methods Base64 Convert to

List of utility methods to do Base64 Convert to

Description

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

Method

byte[]base642byte(String base64)
basebyte
BASE64Decoder base64Decoder = new BASE64Decoder();
return base64Decoder.decodeBuffer(base64);
InputStreambase64StrToStream(String base64Str)
base Str To Stream
if (base64Str == null) {
    throw new NullPointerException();
BASE64Decoder decoder = new BASE64Decoder();
byte[] b = decoder.decodeBuffer(base64Str);
return byteTostream(b);
byte[]base64ToByte(String data)
From a base 64 representation, returns the corresponding byte[]
BASE64Decoder decoder = new BASE64Decoder();
return decoder.decodeBuffer(data);
byte[]base64ToByteArray(String data)
Converts a base64 encoded string to a byte array
if (data == null) {
    return null;
if (data.length() % 4 != 0) {
    return null;
ByteArrayOutputStream result = new ByteArrayOutputStream();
int offset = 0;
...
voidbase64ToFile(String base64Code, String targetPath)
base64 code save to file
byte[] buffer = base64Code.getBytes();
FileOutputStream out = new FileOutputStream(targetPath);
out.write(buffer);
out.close();
byte[]fromBase64(byte[] buf, int start, int length)
from Base
byte[] foo = new byte[length];
int j = 0;
for (int i = start; i < start + length; i += 4) {
    foo[j] = (byte) ((val(buf[i]) << 2) | ((val(buf[i + 1]) & 0x30) >>> 4));
    if (buf[i + 2] == (byte) '=') {
        j++;
        break;
    foo[j + 1] = (byte) (((val(buf[i + 1]) & 0x0f) << 4) | ((val(buf[i + 2]) & 0x3c) >>> 2));
    if (buf[i + 3] == (byte) '=') {
        j += 2;
        break;
    foo[j + 2] = (byte) (((val(buf[i + 2]) & 0x03) << 6) | (val(buf[i + 3]) & 0x3f));
    j += 3;
byte[] bar = new byte[j];
System.arraycopy(foo, 0, bar, 0, j);
return bar;
StringfromBase64(final String encoded)
Decode a String from its base64 representation.
final byte[] bytearray = Base64.getDecoder().decode(encoded);
return (new String(bytearray));
byte[]fromBase64(final String input)
Convert Base64 string to byte array.
String tmp = input.replace("\r\n", "");
if (tmp.length() % 4 != 0) {
    throw new IllegalArgumentException("Invalid base64 input");
int len = (tmp.length() * 3) / 4;
int pos = tmp.indexOf('=');
if (pos > 0) {
    len -= tmp.length() - pos;
...
byte[]fromBase64(String base64)
from Base
return Base64.getDecoder().decode(base64);
byte[]fromBase64(String base64Text)
Decodes the specified text with Base64 characters in binary.
return Base64.getDecoder().decode(base64Text);