public class Base64 extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_RESIZE_FACTOR |
static int |
DEFAULT_BUFFER_SIZE |
protected int |
lineLength
Chunksize for encoding.
|
protected static int |
MASK_8BITS
Mask used to extract 8 bits, used in decoding bytes
|
static int |
MIME_CHUNK_SIZE |
protected byte |
PAD |
protected static byte |
PAD_DEFAULT
Byte used to pad output.
|
static int |
PEM_CHUNK_SIZE |
| Modifier | Constructor and Description |
|---|---|
|
Base64()
Creates a Base64 codec used for decoding (all modes) and encoding in
URL-unsafe mode.
|
protected |
Base64(int lineLength) |
|
Base64(int lineLength,
byte[] lineSeparator,
boolean urlSafe)
Creates a Base64 codec used for decoding (all modes) and encoding in
URL-unsafe mode.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
containsAlphabetOrPad(byte[] arrayOctet)
Tests a given byte array to see if it contains any characters within the
alphabet or PAD.
|
Base64Context |
decode(byte[] pArray,
Base64Context ctx)
Decodes a byte[] containing characters in the Base-N alphabet.
|
Base64Context |
decode(byte[] pArray,
int offset,
int length,
Base64Context ctx)
Decodes a byte[] containing characters in the Base-N alphabet.
|
Base64Context |
decode(char[] pArray,
Base64Context ctx)
Decodes a char[] containing characters in the Base-N alphabet.
|
Base64Context |
decode(char[] pArray,
int offset,
int length,
Base64Context ctx)
Decodes a char[] containing characters in the Base-N alphabet.
|
protected int |
getDefaultBufferSize()
Get the default buffer size.
|
protected boolean |
isInAlphabet(byte octet)
Returns whether or not the
octet is in the Base64 alphabet. |
boolean |
isInAlphabet(byte[] arrayOctet,
boolean allowWSPad)
Tests a given byte array to see if it contains only valid characters
within the alphabet.
|
boolean |
isInAlphabet(String basen)
Tests a given String to see if it contains only valid characters within
the alphabet.
|
boolean |
isUrlSafe()
Returns our current encode mode.
|
protected static boolean |
isWhiteSpace(byte byteToCheck)
Checks if a byte value is whitespace or not.
|
public static final int MIME_CHUNK_SIZE
public static final int PEM_CHUNK_SIZE
public static final int DEFAULT_BUFFER_RESIZE_FACTOR
public static final int DEFAULT_BUFFER_SIZE
protected static final int MASK_8BITS
protected static final byte PAD_DEFAULT
protected final byte PAD
protected final int lineLength
public Base64()
When encoding the line length is 0 (no chunking), and the encoding table is STANDARD_ENCODE_TABLE.
When decoding all variants are supported.
protected Base64(int lineLength)
public Base64(int lineLength,
byte[] lineSeparator,
boolean urlSafe)
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. @param 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.
Note: no padding is added when using the URL-safe alphabet.IllegalArgumentException - The provided lineSeparator included some
base64 characters. That's not going to work!public boolean isInAlphabet(byte[] arrayOctet,
boolean allowWSPad)
arrayOctet - byte array to testallowWSPad - if true, then whitespace and PAD are also
allowedtrue if all bytes are valid characters in the alphabet or
if the byte array is empty; false, otherwiseprotected boolean isInAlphabet(byte octet)
octet is in the Base64 alphabet.octet - The value to testtrue if the value is defined in the the Base64 alphabet
false otherwise.protected static boolean isWhiteSpace(byte byteToCheck)
byteToCheck - the byte to checkpublic boolean isInAlphabet(String basen)
basen - String to testtrue if all characters in the String are valid characters
in the alphabet or if the String is empty; false, otherwiseisInAlphabet(byte[], boolean)protected boolean containsAlphabetOrPad(byte[] arrayOctet)
arrayOctet - byte array to testtrue if any byte is a valid character in the alphabet or
PAD; false otherwisepublic boolean isUrlSafe()
protected int getDefaultBufferSize()
DEFAULT_BUFFER_SIZEpublic Base64Context decode(byte[] pArray, Base64Context ctx) throws FileParsingException
pArray - A byte array containing Base-N character datactx - FileParsingExceptionpublic Base64Context decode(byte[] pArray, int offset, int length, Base64Context ctx) throws FileParsingException
pArray - A byte array containing Base-N character dataoffset - length - ctx - FileParsingExceptionpublic Base64Context decode(char[] pArray, Base64Context ctx) throws FileParsingException
pArray - A byte array containing Base-N character datactx - FileParsingExceptionpublic Base64Context decode(char[] pArray, int offset, int length, Base64Context ctx) throws FileParsingException
pArray - A byte array containing Base-N character dataoffset - offset in the input array where the data startslength - length of the data, starting at offset in the input arrayctx - Base64Context or Base64ContextPooled, pooled
version is preferredFileParsingExceptionCopyright © 2017. All rights reserved.