| java.lang.Object | |
| ↳ | org.odata4j.repack.org.apache.commons.codec.binary.Base64 |
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 Bodies by Freed and Borenstein.
The class can be parameterized in the following manner with various constructors:
Since this class operates directly on byte streams, and not character streams, it is hard-coded to only encode/decode character encodings which are compatible with the lower 127 ASCII chart (ISO-8859-1, Windows-1252, UTF-8, etc).
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int | CHUNK_SIZE | Chunk size per RFC 2045 section 6.8. | |||||||||
| int | DEFAULT_BUFFER_RESIZE_FACTOR | ||||||||||
| int | DEFAULT_BUFFER_SIZE | ||||||||||
| int | MASK_6BITS | Mask used to extract 6 bits, used when encoding | |||||||||
| int | MASK_8BITS | Mask used to extract 8 bits, used in decoding base64 bytes | |||||||||
| byte | PAD | Byte used to pad output. | |||||||||
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| CHUNK_SEPARATOR | Chunk separator per RFC 2045 section 2.1. | ||||||||||
| DECODE_TABLE | This array is a lookup table that translates Unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer equivalents. | ||||||||||
| STANDARD_ENCODE_TABLE | This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" equivalents as specified in Table 1 of RFC 2045. | ||||||||||
| URL_SAFE_ENCODE_TABLE | This is a copy of the STANDARD_ENCODE_TABLE above, but with + and / changed to - and _ to make the encoded Base64 results more URL-SAFE. | ||||||||||
| buffer | Buffer for streaming. | ||||||||||
| currentLinePos | Variable tracks how many characters have been written to the current line. | ||||||||||
| decodeSize | Convenience variable to help us determine when our buffer is going to run out of room and needs resizing. | ||||||||||
| encodeSize | Convenience variable to help us determine when our buffer is going to run out of room and needs resizing. | ||||||||||
| encodeTable | Encode table to use: either STANDARD or URL_SAFE. | ||||||||||
| eof | Boolean flag to indicate the EOF has been reached. | ||||||||||
| lineLength | Line length for encoding. | ||||||||||
| lineSeparator | Line separator for encoding. | ||||||||||
| modulus | Writes to the buffer only occur after every 3 reads when encoding, an every 4 reads when decoding. | ||||||||||
| pos | Position where next character should be written in the buffer. | ||||||||||
| readPos | Position where next character should be read from the buffer. | ||||||||||
| x | Place holder for the 3 bytes we're dealing with for our base64 logic. | ||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
| |||||||||||
Creates a Base64 codec used for decoding (all modes) and encoding in the given URL-safe mode.
| |||||||||||
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
| |||||||||||
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
| |||||||||||
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Decodes a byte[] containing containing characters in the Base64 alphabet.
| |||||||||||
Decodes an Object using the base64 algorithm.
| |||||||||||
Decodes a String containing containing characters in the Base64 alphabet.
| |||||||||||
Decodes a Base64 String into octets
| |||||||||||
Decodes Base64 data into octets
| |||||||||||
Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
| |||||||||||
Encodes an Object using the base64 algorithm.
| |||||||||||
Encodes a byte[] containing binary data, into a byte[] containing characters in the Base64 alphabet.
| |||||||||||
Encodes binary data using the base64 algorithm but does not chunk the output.
| |||||||||||
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
| |||||||||||
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
| |||||||||||
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
| |||||||||||
Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
| |||||||||||
Encodes binary data using the base64 algorithm into 76 character blocks separated by CRLF.
| |||||||||||
Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output.
| |||||||||||
Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output.
| |||||||||||
Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
| |||||||||||
Encodes a byte[] containing binary data, into a String containing characters in the Base64 alphabet.
| |||||||||||
Tests a given byte array to see if it contains only valid characters within the Base64 alphabet.
| |||||||||||
Returns whether or not the
octet is in the base 64 alphabet. | |||||||||||
Returns our current encode mode.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
org.odata4j.repack.org.apache.commons.codec.BinaryDecoder
| |||||||||||
From interface
org.odata4j.repack.org.apache.commons.codec.BinaryEncoder
| |||||||||||
From interface
org.odata4j.repack.org.apache.commons.codec.Decoder
| |||||||||||
From interface
org.odata4j.repack.org.apache.commons.codec.Encoder
| |||||||||||
Chunk size per RFC 2045 section 6.8.
The {@value } character limit does not count the trailing CRLF, but counts all other characters, including any equal signs.
Mask used to extract 6 bits, used when encoding
Mask used to extract 8 bits, used in decoding base64 bytes
Byte used to pad output.
Chunk separator per RFC 2045 section 2.1.
N.B. The next major release may break compatibility and make this field private.
This array is a lookup table that translates Unicode characters drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045) into their 6-bit positive integer equivalents. Characters that are not in the Base64 alphabet but fall within the bounds of the array are translated to -1. Note: '+' and '-' both decode to 62. '/' and '_' both decode to 63. This means decoder seamlessly handles both URL_SAFE and STANDARD base64. (The encoder, on the other hand, needs to know ahead of time what to emit). Thanks to "commons" project in ws.apache.org for this code. http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
This array is a lookup table that translates 6-bit positive integer index values into their "Base64 Alphabet" equivalents as specified in Table 1 of RFC 2045. Thanks to "commons" project in ws.apache.org for this code. http://svn.apache.org/repos/asf/webservices/commons/trunk/modules/util/
This is a copy of the STANDARD_ENCODE_TABLE above, but with + and / changed to - and _ to make the encoded Base64 results more URL-SAFE. This table is only used when the Base64's mode is set to URL-SAFE.
Buffer for streaming.
Variable tracks how many characters have been written to the current line. Only used when encoding. We use it to make sure each encoded line never goes beyond lineLength (if lineLength > 0).
Convenience variable to help us determine when our buffer is going to run out of room and needs resizing. decodeSize = 3 + lineSeparator.length;
Convenience variable to help us determine when our buffer is going to run out of room and needs resizing. encodeSize = 4 + lineSeparator.length;
Encode table to use: either STANDARD or URL_SAFE. Note: the DECODE_TABLE above remains static because it is able to decode both STANDARD and URL_SAFE streams, but the encodeTable must be a member variable so we can switch between the two modes.
Boolean flag to indicate the EOF has been reached. Once EOF has been reached, this Base64 object becomes useless, and must be thrown away.
Line length for encoding. Not used when decoding. A value of zero or less implies no chunking of the base64 encoded data.
Line separator for encoding. Not used when decoding. Only used if lineLength > 0.
Writes to the buffer only occur after every 3 reads when encoding, an every 4 reads when decoding. This variable helps track that.
Position where next character should be written in the buffer.
Position where next character should be read from the buffer.
Place holder for the 3 bytes we're dealing with for our base64 logic. Bitwise operations store and extract the base64 encoding or decoding from this variable.
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
When encoding the line length is 76, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
When decoding all variants are supported.
Creates a Base64 codec used for decoding (all modes) and encoding in the given URL-safe mode.
When encoding the line length is 76, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
When decoding all variants are supported.
| urlSafe | If true, URL-safe encoding is used. In most cases this should be set to false. |
|---|
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
When encoding the line length is given in the constructor, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
When decoding all variants are supported.
| lineLength | Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding. |
|---|
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
When encoding the line length and line separator are given in the constructor, and the encoding table is STANDARD_ENCODE_TABLE.
Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
When decoding all variants are supported.
| lineLength | Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding. |
|---|---|
| lineSeparator | Each line of encoded data will end with this sequence of bytes. |
| IllegalArgumentException | Thrown when the provided lineSeparator included some base64 characters. |
|---|
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.
When encoding the line length and line separator are given in the constructor, and the encoding table is STANDARD_ENCODE_TABLE.
Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
When decoding all variants are supported.
| lineLength | Each line of encoded data will be at most of the given length (rounded down to nearest multiple of 4). If lineLength <= 0, then the output will not be divided into lines (chunks). Ignored when decoding. |
|---|---|
| lineSeparator | Each line of encoded data will end with this sequence of bytes. |
| urlSafe | Instead of emitting '+' and '/' we emit '-' and '_' respectively. urlSafe is only applied to encode operations. Decoding seamlessly handles both modes. |
| IllegalArgumentException | The provided lineSeparator included some base64 characters. That's not going to work! |
|---|
Decodes a byte[] containing containing characters in the Base64 alphabet.
| pArray | A byte array containing Base64 character data |
|---|
Decodes an Object using the base64 algorithm. This method is provided in order to satisfy the requirements of the Decoder interface, and will throw a DecoderException if the supplied object is not of type byte[] or String.
| pObject | Object to decode |
|---|
| DecoderException | if the parameter supplied is not of type byte[] |
|---|
Decodes a String containing containing characters in the Base64 alphabet.
| pArray | A String containing Base64 character data |
|---|
Decodes a Base64 String into octets
| base64String | String containing Base64 data |
|---|
Decodes Base64 data into octets
| base64Data | Byte array containing Base64 data |
|---|
Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
| pArray | A byte array containing base64 character data |
|---|
Encodes an Object using the base64 algorithm. This method is provided in order to satisfy the requirements of the Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[].
| pObject | Object to encode |
|---|
| EncoderException | if the parameter supplied is not of type byte[] |
|---|
Encodes a byte[] containing binary data, into a byte[] containing characters in the Base64 alphabet.
| pArray | A byte array containing binary data |
|---|
Encodes binary data using the base64 algorithm but does not chunk the output.
| binaryData | Binary data to encode |
|---|
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
| binaryData | Array containing binary data to encode. |
|---|---|
| isChunked | If true this encoder will chunk the base64 output into 76 character blocks |
| IllegalArgumentException | Thrown when the input array needs an output array bigger than MAX_VALUE
|
|---|
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
| binaryData | Array containing binary data to encode. |
|---|---|
| isChunked | If true this encoder will chunk the base64 output into 76 character blocks |
| urlSafe | If true this encoder will emit - and _ instead of the usual + and / characters. |
| maxResultSize | The maximum result size to accept. |
| IllegalArgumentException | Thrown when the input array needs an output array bigger than maxResultSize |
|---|
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks.
| binaryData | Array containing binary data to encode. |
|---|---|
| isChunked | If true this encoder will chunk the base64 output into 76 character blocks |
| urlSafe | If true this encoder will emit - and _ instead of the usual + and / characters. |
| IllegalArgumentException | Thrown when the input array needs an output array bigger than MAX_VALUE |
|---|
Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks
| binaryData | Binary data to encode |
|---|
Encodes binary data using the base64 algorithm into 76 character blocks separated by CRLF.
| binaryData | Binary data to encode |
|---|
Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The url-safe variation emits - and _ instead of + and / characters.
| binaryData | Binary data to encode |
|---|
Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. The url-safe variation emits - and _ instead of + and / characters.
| binaryData | Binary data to encode |
|---|
Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature
| bigInt | A BigInteger |
|---|
| NullPointerException | if null is passed in |
|---|
Encodes a byte[] containing binary data, into a String containing characters in the Base64 alphabet.
| pArray | A byte array containing binary data |
|---|
Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. Currently the method treats whitespace as valid.
| arrayOctet | Byte array to test |
|---|
true if all bytes are valid characters in the Base64 alphabet or if the byte array is empty; false, otherwise
Returns whether or not the octet is in the base 64 alphabet.
| octet | The value to test |
|---|
true if the value is defined in the the base 64 alphabet, false otherwise.Returns our current encode mode. True if we're URL-SAFE, false otherwise.