Package org.codehaus.stax2.ri.typed
Class Base64DecoderBase
- java.lang.Object
-
- org.codehaus.stax2.ri.typed.Base64DecoderBase
-
- Direct Known Subclasses:
CharArrayBase64Decoder
,StringBase64Decoder
abstract class Base64DecoderBase extends java.lang.Object
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
Fields Modifier and Type Field Description (package private) Stax2Util.ByteAggregator
_byteAggr
(package private) int
_decodedData
Data decoded and/or ready to be output.(package private) int
_state
State of the state machine(package private) Base64Variant
_variant
Details of base64 variant (alphabet in use, padding, line length) are contained in and accessed via this object.(package private) static int
INT_SPACE
(package private) static int
STATE_INITIAL
Initial state is where we start, and where white space is accepted.(package private) static int
STATE_OUTPUT_1
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 int
STATE_OUTPUT_2
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 int
STATE_OUTPUT_3
State in which we have succesfully decoded a full triplet, but not yet output any characters(package private) static int
STATE_VALID_1
State in which we have gotten one valid non-padding base64 encoded character(package private) static int
STATE_VALID_2
State in which we have gotten two valid non-padding base64 encoded characters.(package private) static int
STATE_VALID_2_AND_PADDING
State in which we have gotten two valid non-padding base64 encoded characters, followed by a single padding character.(package private) static int
STATE_VALID_3
State in which we have gotten three valid non-padding base64 encoded characters.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Base64DecoderBase()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
decode(byte[] resultBuffer, int resultOffset, int maxLength)
Method that does actual decodingbyte[]
decodeCompletely()
Method that can be called to completely decode content that this decoder has been initialized with.int
endOfContent()
Method called to indicate that we have no more encoded content to process, and decoding is to finish.Stax2Util.ByteAggregator
getByteAggregator()
boolean
hasData()
Method that can be called to check if this decoder is in has unflushed data ready to be returned.protected java.lang.IllegalArgumentException
reportInvalidChar(char ch, int bindex)
protected java.lang.IllegalArgumentException
reportInvalidChar(char ch, int bindex, java.lang.String msg)
-
-
-
Field Detail
-
STATE_INITIAL
static final int STATE_INITIAL
Initial state is where we start, and where white space is accepted.- See Also:
- Constant Field Values
-
STATE_VALID_1
static final int STATE_VALID_1
State in which we have gotten one valid non-padding base64 encoded character- See Also:
- Constant Field Values
-
STATE_VALID_2
static final int STATE_VALID_2
State in which we have gotten two valid non-padding base64 encoded characters.- See Also:
- Constant Field Values
-
STATE_VALID_3
static final int STATE_VALID_3
State in which we have gotten three valid non-padding base64 encoded characters.- See Also:
- Constant Field Values
-
STATE_OUTPUT_3
static final int STATE_OUTPUT_3
State in which we have succesfully decoded a full triplet, but not yet output any characters- See Also:
- Constant Field Values
-
STATE_OUTPUT_2
static final int STATE_OUTPUT_2
State in which we have 2 decoded bytes to output (either due to partial triplet, or having output one byte from full triplet).- See Also:
- Constant Field Values
-
STATE_OUTPUT_1
static final int STATE_OUTPUT_1
State in which we have 1 decoded byte to output (either due to partial triplet, or having output some of decoded bytes earlier)- See Also:
- Constant Field Values
-
STATE_VALID_2_AND_PADDING
static final int STATE_VALID_2_AND_PADDING
State 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:
- Constant Field Values
-
INT_SPACE
static final int INT_SPACE
- See Also:
- Constant Field Values
-
_variant
Base64Variant _variant
Details 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 _state
State of the state machine
-
_decodedData
int _decodedData
Data 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
-
-
Method Detail
-
decode
public abstract int decode(byte[] resultBuffer, int resultOffset, int maxLength) throws java.lang.IllegalArgumentException
Method that does actual decoding- Throws:
java.lang.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
public Stax2Util.ByteAggregator getByteAggregator()
-
reportInvalidChar
protected java.lang.IllegalArgumentException reportInvalidChar(char ch, int bindex) throws java.lang.IllegalArgumentException
- Throws:
java.lang.IllegalArgumentException
-
reportInvalidChar
protected java.lang.IllegalArgumentException reportInvalidChar(char ch, int bindex, java.lang.String msg) throws java.lang.IllegalArgumentException
- Parameters:
bindex
- Relative index within base64 character unit; between 0 and 3 (as unit has exactly 4 characters)- Throws:
java.lang.IllegalArgumentException
-
-