Package org.codehaus.stax2.ri.typed
Class Base64DecoderBase
java.lang.Object
org.codehaus.stax2.ri.typed.Base64DecoderBase
- Direct Known Subclasses:
CharArrayBase64Decoder
,StringBase64Decoder
Abstract base class used to share functionality between concrete
base64 decoders.
Mostly what follows is just shared definitions of the state machine states to use, but there is also shared convenience functionality for convenience decoding into simple byte arrays.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Stax2Util.ByteAggregator
(package private) int
Data decoded and/or ready to be output.(package private) int
State of the state machine(package private) Base64Variant
Details of base64 variant (alphabet in use, padding, line length) are contained in and accessed via this object.(package private) static final int
(package private) static final int
Initial state is where we start, and where white space is accepted.(package private) static final int
State in which we have 1 decoded byte to output (either due to partial triplet, or having output some of decoded bytes earlier)(package private) static final int
State in which we have 2 decoded bytes to output (either due to partial triplet, or having output one byte from full triplet).(package private) static final int
State in which we have succesfully decoded a full triplet, but not yet output any characters(package private) static final int
State in which we have gotten one valid non-padding base64 encoded character(package private) static final int
State in which we have gotten two valid non-padding base64 encoded characters.(package private) static final int
State in which we have gotten two valid non-padding base64 encoded characters, followed by a single padding character.(package private) static final int
State in which we have gotten three valid non-padding base64 encoded characters. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract int
decode
(byte[] resultBuffer, int resultOffset, int maxLength) Method that does actual decodingbyte[]
Method that can be called to completely decode content that this decoder has been initialized with.final int
Method called to indicate that we have no more encoded content to process, and decoding is to finish.final boolean
hasData()
Method that can be called to check if this decoder is in has unflushed data ready to be returned.protected IllegalArgumentException
reportInvalidChar
(char ch, int bindex) protected IllegalArgumentException
reportInvalidChar
(char ch, int bindex, String msg)
-
Field Details
-
STATE_INITIAL
static final int STATE_INITIALInitial state is where we start, and where white space is accepted.- See Also:
-
STATE_VALID_1
static final int STATE_VALID_1State in which we have gotten one valid non-padding base64 encoded character- See Also:
-
STATE_VALID_2
static final int STATE_VALID_2State in which we have gotten two valid non-padding base64 encoded characters.- See Also:
-
STATE_VALID_3
static final int STATE_VALID_3State in which we have gotten three valid non-padding base64 encoded characters.- See Also:
-
STATE_OUTPUT_3
static final int STATE_OUTPUT_3State in which we have succesfully decoded a full triplet, but not yet output any characters- See Also:
-
STATE_OUTPUT_2
static final int STATE_OUTPUT_2State in which we have 2 decoded bytes to output (either due to partial triplet, or having output one byte from full triplet).- See Also:
-
STATE_OUTPUT_1
static final int STATE_OUTPUT_1State in which we have 1 decoded byte to output (either due to partial triplet, or having output some of decoded bytes earlier)- See Also:
-
STATE_VALID_2_AND_PADDING
static final int STATE_VALID_2_AND_PADDINGState in which we have gotten two valid non-padding base64 encoded characters, followed by a single padding character. This means that we must get one more padding character to be able to decode the single encoded byte- See Also:
-
INT_SPACE
static final int INT_SPACE- See Also:
-
_variant
Base64Variant _variantDetails of base64 variant (alphabet in use, padding, line length) are contained in and accessed via this object. It is passed through init methods. -
_state
int _stateState of the state machine -
_decodedData
int _decodedDataData decoded and/or ready to be output. Alignment and storage format depend on state: during decoding things are appended from lowest significant bits, and during output, flushed from more significant bytes. -
_byteAggr
Stax2Util.ByteAggregator _byteAggr
-
-
Constructor Details
-
Base64DecoderBase
protected Base64DecoderBase()
-
-
Method Details
-
decode
public abstract int decode(byte[] resultBuffer, int resultOffset, int maxLength) throws IllegalArgumentException Method that does actual decoding- Throws:
IllegalArgumentException
-
hasData
public final boolean hasData()Method that can be called to check if this decoder is in has unflushed data ready to be returned. -
endOfContent
public final int endOfContent()Method called to indicate that we have no more encoded content to process, and decoding is to finish. Depending base64 variant in use, this means one of three things:- We are waiting for start of a new segment; no data to decode, ok to quit (returns 0)
- We are half-way through decoding for padding variant (or, non-padding with just partial byte [single char]); error case. (returns -1)
- We are half-way through decoding for non-padding variant, and thereby have 1 or 2 bytes of data (which was not earlier recognized because of missing padding characters) (returns 1 or 2, number of bytes made available)
-
decodeCompletely
public byte[] decodeCompletely()Method that can be called to completely decode content that this decoder has been initialized with. -
getByteAggregator
-
reportInvalidChar
protected IllegalArgumentException reportInvalidChar(char ch, int bindex) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
reportInvalidChar
protected IllegalArgumentException reportInvalidChar(char ch, int bindex, String msg) throws IllegalArgumentException - Parameters:
bindex
- Relative index within base64 character unit; between 0 and 3 (as unit has exactly 4 characters)- Throws:
IllegalArgumentException
-