Provides Base64 encoding and decoding as defined by RFC 2045 . This class implements section 6.8. Base64 Content-Transfer-Encoding from RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message
| 52 | * @since 1.0 |
| 53 | */ |
| 54 | public class Base64 extends BaseNCodec { |
| 55 | |
| 56 | /** |
| 57 | * BASE32 characters are 6 bits in length. |
| 58 | * They are formed by taking a block of 3 octets to form a 24-bit string, |
| 59 | * which is converted into 4 BASE64 characters. |
| 60 | */ |
| 61 | private static final int BITS_PER_ENCODED_BYTE = 6; |
| 62 | private static final int BYTES_PER_UNENCODED_BLOCK = 3; |
| 63 | private static final int BYTES_PER_ENCODED_BLOCK = 4; |
| 64 | |
| 65 | /** |
| 66 | * Chunk separator per RFC 2045 section 2.1. |
| 67 | * |
| 68 | * <p> |
| 69 | * N.B. The next major release may break compatibility and make this field private. |
| 70 | * </p> |
| 71 | * |
| 72 | * @see <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045 section 2.1</a> |
| 73 | */ |
| 74 | static final byte[] CHUNK_SEPARATOR = {'\r', '\n'}; |
| 75 | |
| 76 | /** |
| 77 | * This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" |
| 78 | * equivalents as specified in Table 1 of RFC 2045. |
| 79 | * |
| 80 | * Thanks to "commons" project in ws.apache.org for this code. |
| 81 | * http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/ |
| 82 | */ |
| 83 | private static final byte[] STANDARD_ENCODE_TABLE = { |
| 84 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', |
| 85 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', |
| 86 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', |
| 87 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', |
| 88 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' |
| 89 | }; |
| 90 | |
| 91 | /** |
| 92 | * This is a copy of the STANDARD_ENCODE_TABLE above, but with + and / |
| 93 | * changed to - and _ to make the encoded Base64 results more URL-SAFE. |
| 94 | * This table is only used when the Base64's mode is set to URL-SAFE. |
| 95 | */ |
| 96 | private static final byte[] URL_SAFE_ENCODE_TABLE = { |
| 97 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', |
| 98 | 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', |
| 99 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', |
| 100 | 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', |
| 101 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_' |
| 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * This array is a lookup table that translates Unicode characters drawn from the "Base64 Alphabet" (as specified |
| 106 | * in Table 1 of RFC 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64 |
| 107 | * alphabet but fall within the bounds of the array are translated to -1. |
| 108 | * |
| 109 | * Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63. This means decoder seamlessly handles both |
| 110 | * URL_SAFE and STANDARD base64. (The encoder, on the other hand, needs to know ahead of time what to emit). |
| 111 | * |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…