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