return out;
}
public static String base64decode(String base64Str) throws Base64Exception {
if(!Base64.isBase64(base64Str)) {
throw new Base64Exception("Provided string is not Base64 encoded");
}
byte[] out = base64decodeByteArray(base64Str);
CharsetDecoder decoder = Charsets.UTF_8.newDecoder();
try {
decoder.onMalformedInput(CodingErrorAction.REPORT);
decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
CharBuffer buffer = decoder.decode(
ByteBuffer.wrap(Arrays.copyOf(out, out.length)));
return buffer.toString();
}
catch(MalformedInputException ex) {
throw new Base64Exception("Input is malformed", ex);
}
catch(UnmappableCharacterException ex) {
throw new Base64Exception("Unmappable characters found", ex);
}
catch(CharacterCodingException ex) {
throw new Base64Exception(ex);
}
}