Java Utililty Methods XML Base64 Encode Decode

List of utility methods to do XML Base64 Encode Decode

Description

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

Method

Stringbase64Encode(String data)
Encode the given string with Base64
return DatatypeConverter.printBase64Binary(data.getBytes("UTF-8"));
Stringbase64EncodeBasicCredentials(String username, String password)
Base64-encodes the specified username and password for Basic Authorization for HTTP requests or upstream proxy authorization.
String credentialsToEncode = username + ':' + password;
byte[] credentialsAsUtf8Bytes = credentialsToEncode.getBytes(StandardCharsets.UTF_8);
return DatatypeConverter.printBase64Binary(credentialsAsUtf8Bytes);
Stringbase64FromBinary(byte[] value)
Convert (encode) the given binary value using Base64.
return DatatypeConverter.printBase64Binary(value);
Stringbase64FromString(String value)
Convert the given String to UTF-8, encode the result with Base64, and return the encoded value as a string.
return DatatypeConverter.printBase64Binary(toBytes(value));
byte[]base64ToByte(String data)
From a base 64 representation, returns the corresponding byte[]
return DatatypeConverter.parseBase64Binary(data);
StringbyteArrayToBase64String(byte[] data)
byte Array To Base String
return DatatypeConverter.printBase64Binary(data);
StringBytesToBase64String(final byte[] value)
Bytes To Base String
return DatatypeConverter.printBase64Binary(value);
StringbyteToBase64(byte[] data)
byte To Base
return DatatypeConverter.printBase64Binary(data);
StringcompressToBase64(byte[] message)
compress To Base
return DatatypeConverter.printBase64Binary(compress(message));
StringcreateBase64EncodedStringFromURL(URL url)
create Base Encoded String From URL
final InputStream inputStream = url.openStream();
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
    outputStream.write(buffer, 0, bytesRead);
outputStream.close();
...