public final class Base64Variant extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected int |
_maxLineLength
Maximum number of encoded base64 characters to output during encoding
before adding a linefeed, if line length is to be limited
(
Integer.MAX_VALUE if not limited). |
protected String |
_name
Symbolic name of variant; used for diagnostics/debugging.
|
protected char |
_paddingChar
Characted used for padding, if any (
PADDING_CHAR_NONE if not). |
protected boolean |
_usesPadding
Whether this variant uses padding or not.
|
static int |
BASE64_VALUE_INVALID
Marker used to denote ascii characters that do not correspond
to a 6-bit value (in this variant), and is not used as a padding
character.
|
static int |
BASE64_VALUE_PADDING
Marker used to denote ascii character (in decoding table) that
is the padding character using this variant (if any).
|
Constructor and Description |
---|
Base64Variant(Base64Variant base,
String name,
boolean usesPadding,
char paddingChar,
int maxLineLength)
"Copy constructor" that can be used when the base alphabet is identical
to one used by another variant, but other details (padding, maximum
line length) differ
|
Base64Variant(Base64Variant base,
String name,
int maxLineLength)
"Copy constructor" that can be used when the base alphabet is identical
to one used by another variant except for the maximum line length
(and obviously, name).
|
Base64Variant(String name,
String base64Alphabet,
boolean usesPadding,
char paddingChar,
int maxLineLength) |
Modifier and Type | Method and Description |
---|---|
protected void |
_reportBase64EOF() |
protected void |
_reportInvalidBase64(char ch,
int bindex,
String msg) |
byte[] |
decode(String input)
Convenience method for decoding contents of a Base64-encoded String,
using this variant's settings.
|
void |
decode(String str,
ByteArrayBuilder builder)
Convenience method for decoding contents of a Base64-encoded String,
using this variant's settings
and appending decoded binary data using provided
ByteArrayBuilder . |
int |
decodeBase64Byte(byte b) |
int |
decodeBase64Char(char c) |
int |
decodeBase64Char(int ch) |
String |
encode(byte[] input)
Convenience method for converting given byte array as base64 encoded
String using this variant's settings.
|
String |
encode(byte[] input,
boolean addQuotes)
Convenience method for converting given byte array as base64 encoded String
using this variant's settings,
optionally enclosed in double-quotes.
|
byte |
encodeBase64BitsAsByte(int value) |
char |
encodeBase64BitsAsChar(int value) |
int |
encodeBase64Chunk(int b24,
byte[] buffer,
int ptr)
Method that encodes given right-aligned (LSB) 24-bit value
into 4 base64 bytes (ascii), stored in given result buffer.
|
int |
encodeBase64Chunk(int b24,
char[] buffer,
int ptr)
Method that encodes given right-aligned (LSB) 24-bit value
into 4 base64 characters, stored in given result buffer.
|
void |
encodeBase64Chunk(StringBuilder sb,
int b24) |
int |
encodeBase64Partial(int bits,
int outputBytes,
byte[] buffer,
int outPtr)
Method that outputs partial chunk (which only encodes one
or two bytes of data).
|
int |
encodeBase64Partial(int bits,
int outputBytes,
char[] buffer,
int outPtr)
Method that outputs partial chunk (which only encodes one
or two bytes of data).
|
void |
encodeBase64Partial(StringBuilder sb,
int bits,
int outputBytes) |
boolean |
equals(Object o) |
int |
getMaxLineLength() |
String |
getName() |
byte |
getPaddingByte() |
char |
getPaddingChar() |
int |
hashCode() |
protected Object |
readResolve()
Method used to "demote" deserialized instances back to
canonical ones
|
String |
toString() |
boolean |
usesPadding() |
boolean |
usesPaddingChar(char c) |
boolean |
usesPaddingChar(int ch) |
public static final int BASE64_VALUE_INVALID
public static final int BASE64_VALUE_PADDING
protected final String _name
Note that this is the only non-transient field; used when reading back from serialized state
protected final transient boolean _usesPadding
protected final transient char _paddingChar
PADDING_CHAR_NONE
if not).protected final transient int _maxLineLength
Integer.MAX_VALUE
if not limited).
Note: for some output modes (when writing attributes) linefeeds may need to be avoided, and this value ignored.
public Base64Variant(String name, String base64Alphabet, boolean usesPadding, char paddingChar, int maxLineLength)
public Base64Variant(Base64Variant base, String name, int maxLineLength)
public Base64Variant(Base64Variant base, String name, boolean usesPadding, char paddingChar, int maxLineLength)
protected Object readResolve()
public String getName()
public boolean usesPadding()
public boolean usesPaddingChar(char c)
public boolean usesPaddingChar(int ch)
public char getPaddingChar()
public byte getPaddingByte()
public int getMaxLineLength()
public int decodeBase64Char(char c)
public int decodeBase64Char(int ch)
public int decodeBase64Byte(byte b)
public char encodeBase64BitsAsChar(int value)
public int encodeBase64Chunk(int b24, char[] buffer, int ptr)
public void encodeBase64Chunk(StringBuilder sb, int b24)
public int encodeBase64Partial(int bits, int outputBytes, char[] buffer, int outPtr)
outputBytes
- Number of encoded bytes included (either 1 or 2)public void encodeBase64Partial(StringBuilder sb, int bits, int outputBytes)
public byte encodeBase64BitsAsByte(int value)
public int encodeBase64Chunk(int b24, byte[] buffer, int ptr)
public int encodeBase64Partial(int bits, int outputBytes, byte[] buffer, int outPtr)
outputBytes
- Number of encoded bytes included (either 1 or 2)public String encode(byte[] input)
input
- Byte array to encodepublic String encode(byte[] input, boolean addQuotes)
input
- Byte array to encodeaddQuotes
- Whether to surround resulting value in double quotes or notpublic byte[] decode(String input) throws IllegalArgumentException
input
- IllegalArgumentException
- if input is not valid base64 encoded datapublic void decode(String str, ByteArrayBuilder builder) throws IllegalArgumentException
ByteArrayBuilder
.
NOTE: builder will NOT be reset before decoding (nor cleared afterwards); assumption is that caller will ensure it is given in proper state, and used as appropriate afterwards.
IllegalArgumentException
- if input is not valid base64 encoded dataprotected void _reportInvalidBase64(char ch, int bindex, String msg) throws IllegalArgumentException
bindex
- Relative index within base64 character unit; between 0
and 3 (as unit has exactly 4 characters)IllegalArgumentException
protected void _reportBase64EOF() throws IllegalArgumentException
IllegalArgumentException
Copyright © 2014 FasterXML. All Rights Reserved.