Identical to the Base64 encoding defined by RFC 1521 and allows a character set to be specified. RFC 1522 describes techniques to allow the encoding of non-ASCII text in various portions of a RFC
| 43 | * @since 1.3 |
| 44 | */ |
| 45 | public class BCodec extends RFC1522Codec implements StringEncoder, StringDecoder { |
| 46 | /** |
| 47 | * The default Charset used for string decoding and encoding. |
| 48 | */ |
| 49 | private final Charset charset; |
| 50 | |
| 51 | /** |
| 52 | * Default constructor. |
| 53 | */ |
| 54 | public BCodec() { |
| 55 | this(StandardCharsets.UTF_8); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Constructor which allows for the selection of a default Charset |
| 60 | * |
| 61 | * @param charset |
| 62 | * the default string Charset to use. |
| 63 | * |
| 64 | * @see <a href="http://download.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard charsets</a> |
| 65 | * @since 1.7 |
| 66 | */ |
| 67 | public BCodec(final Charset charset) { |
| 68 | this.charset = charset; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Constructor which allows for the selection of a default Charset |
| 73 | * |
| 74 | * @param charsetName |
| 75 | * the default Charset to use. |
| 76 | * @throws java.nio.charset.UnsupportedCharsetException |
| 77 | * If the named Charset is unavailable |
| 78 | * @since 1.7 throws UnsupportedCharsetException if the named Charset is unavailable |
| 79 | * @see <a href="http://download.oracle.com/javase/7/docs/api/java/nio/charset/Charset.html">Standard charsets</a> |
| 80 | */ |
| 81 | public BCodec(final String charsetName) { |
| 82 | this(Charset.forName(charsetName)); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | protected String getEncoding() { |
| 87 | return "B"; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | protected byte[] doEncoding(final byte[] bytes) { |
| 92 | if (bytes == null) { |
| 93 | return null; |
| 94 | } |
| 95 | return Base64.encodeBase64(bytes); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | protected byte[] doDecoding(final byte[] bytes) { |
| 100 | if (bytes == null) { |
| 101 | return null; |
| 102 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…