Top Description Fields Constructors Methods
org.codehaus.stax2.typed

public final Class Base64Variant

extends Object
Class Inheritance
Imports
java.util.Arrays

This abstract base class is used to define specific details of which variant of Base64 encoding/decoding is to be used. Although there is somewhat standard basic version (so-called "MIME Base64"), other variants exists, see Base64 Wikipedia entry for details.

Implementation Notes

Author
Tatu Saloranta
Since
3.0.0

Field Summary

Modifier and TypeField and Description
private final int[]
_asciiToBase64

Decoding table used for base 64 decoding.

private final byte[]
_base64ToAsciiB

Alternative encoding table used for base 64 decoding when output is done as ascii bytes.

private final char[]
_base64ToAsciiC

Encoding table used for base 64 decoding when output is done as characters.

pack-priv final int
_maxLineLength

Maximum number of encoded base64 characters to output during encoding before adding a linefeed, if line length is to be limited (java.lang.Integer#MAX_VALUE if not limited).

pack-priv final String
_name

Symbolic name of variant; used for diagnostics/debugging.

pack-priv final char
_paddingChar

Characted used for padding, if any (PADDING_CHAR_NONE if not).

pack-priv final boolean
_usesPadding

Whether this variant uses padding or not.

public static final 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.

public static final int
BASE64_VALUE_PADDING

Marker used to denote ascii character (in decoding table) that is the padding character using this variant (if any).

pack-priv static final char
PADDING_CHAR_NONE

Placeholder used by "no padding" variant, to be used when a character value is needed.

Constructor Summary

AccessConstructor and Description
public
Base64Variant(String name, String base64Alphabet, boolean usesPadding, char paddingChar, int maxLineLength)

public
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).

public
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

Method Summary

Modifier and TypeMethod and Description
public int
public int

Returns:

6-bit decoded value, if valid character;
decodeBase64Char
(char c)

public byte
public char
public 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.

public 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.

public int
encodeBase64Partial(int bits, int
Number of encoded bytes included (either 1 or 2)
outputBytes
,
char[] buffer, int outPtr)

Method that outputs partial chunk (which only encodes one or two bytes of data).

public int
encodeBase64Partial(int bits, int
Number of encoded bytes included (either 1 or 2)
outputBytes
,
byte[] buffer, int outPtr)

Method that outputs partial chunk (which only encodes one or two bytes of data).

public int
public String
public byte
public char
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public boolean
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_asciiToBase64back to summary
private final int[] _asciiToBase64

Decoding table used for base 64 decoding.

_base64ToAsciiBback to summary
private final byte[] _base64ToAsciiB

Alternative encoding table used for base 64 decoding when output is done as ascii bytes.

_base64ToAsciiCback to summary
private final char[] _base64ToAsciiC

Encoding table used for base 64 decoding when output is done as characters.

_maxLineLengthback to summary
pack-priv final int _maxLineLength

Maximum number of encoded base64 characters to output during encoding before adding a linefeed, if line length is to be limited (java.lang.Integer#MAX_VALUE if not limited).

Note

for some output modes (when writing attributes) linefeeds may need to be avoided, and this value ignored.

_nameback to summary
pack-priv final String _name

Symbolic name of variant; used for diagnostics/debugging.

_paddingCharback to summary
pack-priv final char _paddingChar

Characted used for padding, if any (PADDING_CHAR_NONE if not).

_usesPaddingback to summary
pack-priv final boolean _usesPadding

Whether this variant uses padding or not.

BASE64_VALUE_INVALIDback to summary
public static final 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.

BASE64_VALUE_PADDINGback to summary
public static final int BASE64_VALUE_PADDING

Marker used to denote ascii character (in decoding table) that is the padding character using this variant (if any).

PADDING_CHAR_NONEback to summary
pack-priv static final char PADDING_CHAR_NONE

Placeholder used by "no padding" variant, to be used when a character value is needed.

Constructor Detail

Base64Variantback to summary
public Base64Variant(String name, String base64Alphabet, boolean usesPadding, char paddingChar, int maxLineLength)
Base64Variantback to summary
public 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).

Base64Variantback to summary
public 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

Method Detail

decodeBase64Byteback to summary
public int decodeBase64Byte(byte b)
decodeBase64Charback to summary
public int decodeBase64Char(char c)
Returns:int

6-bit decoded value, if valid character;

encodeBase64BitsAsByteback to summary
public byte encodeBase64BitsAsByte(int value)
encodeBase64BitsAsCharback to summary
public char encodeBase64BitsAsChar(int value)
encodeBase64Chunkback to summary
public 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.

encodeBase64Chunkback to summary
public 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.

encodeBase64Partialback to summary
public int encodeBase64Partial(int bits, int outputBytes, char[] buffer, int outPtr)

Method that outputs partial chunk (which only encodes one or two bytes of data). Data given is still aligned same as if it as full data; that is, missing data is at the "right end" (LSB) of int.

Parameters
outputBytes:int

Number of encoded bytes included (either 1 or 2)

encodeBase64Partialback to summary
public int encodeBase64Partial(int bits, int outputBytes, byte[] buffer, int outPtr)

Method that outputs partial chunk (which only encodes one or two bytes of data). Data given is still aligned same as if it as full data; that is, missing data is at the "right end" (LSB) of int.

Parameters
outputBytes:int

Number of encoded bytes included (either 1 or 2)

getMaxLineLengthback to summary
public int getMaxLineLength()
getNameback to summary
public String getName()
getPaddingByteback to summary
public byte getPaddingByte()
getPaddingCharback to summary
public char getPaddingChar()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
usesPaddingback to summary
public boolean usesPadding()
usesPaddingCharback to summary
public boolean usesPaddingChar(char c)