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

pack-priv abstract Class Base64DecoderBase

extends Object
Class Inheritance
Known Direct Subclasses
org.codehaus.stax2.ri.typed.CharArrayBase64Decoder, org.codehaus.stax2.ri.typed.StringBase64Decoder
Imports
org.codehaus.stax2.typed.Base64Variant, org.codehaus.stax2.ri.Stax2Util

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

Modifier and TypeField and Description
pack-priv Stax2Util.ByteAggregator
pack-priv int
_decodedData

Data decoded and/or ready to be output.

pack-priv int
_state

State of the state machine

pack-priv Base64Variant
_variant

Details of base64 variant (alphabet in use, padding, line length) are contained in and accessed via this object.

pack-priv static final int
pack-priv static final int
STATE_INITIAL

Initial state is where we start, and where white space is accepted.

pack-priv 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)

pack-priv 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).

pack-priv static final int
STATE_OUTPUT_3

State in which we have succesfully decoded a full triplet, but not yet output any characters

pack-priv static final int
STATE_VALID_1

State in which we have gotten one valid non-padding base64 encoded character

pack-priv static final int
STATE_VALID_2

State in which we have gotten two valid non-padding base64 encoded characters.

pack-priv 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.

pack-priv static final int
STATE_VALID_3

State in which we have gotten three valid non-padding base64 encoded characters.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public abstract int
decode(byte[] resultBuffer, int resultOffset, int maxLength)

Method that does actual decoding

public byte[]
decodeCompletely()

Method that can be called to completely decode content that this decoder has been initialized with.

public final int
endOfContent()

Method called to indicate that we have no more encoded content to process, and decoding is to finish.

public Stax2Util.ByteAggregator
public 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
Relative index within base64 character unit; between 0 and 3 (as unit has exactly 4 characters)
bindex
,
String msg)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_byteAggrback to summary
pack-priv Stax2Util.ByteAggregator _byteAggr
_decodedDataback to summary
pack-priv 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.

_stateback to summary
pack-priv int _state

State of the state machine

_variantback to summary
pack-priv 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.

INT_SPACEback to summary
pack-priv static final int INT_SPACE
STATE_INITIALback to summary
pack-priv static final int STATE_INITIAL

Initial state is where we start, and where white space is accepted.

STATE_OUTPUT_1back to summary
pack-priv 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)

STATE_OUTPUT_2back to summary
pack-priv 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).

STATE_OUTPUT_3back to summary
pack-priv static final int STATE_OUTPUT_3

State in which we have succesfully decoded a full triplet, but not yet output any characters

STATE_VALID_1back to summary
pack-priv static final int STATE_VALID_1

State in which we have gotten one valid non-padding base64 encoded character

STATE_VALID_2back to summary
pack-priv static final int STATE_VALID_2

State in which we have gotten two valid non-padding base64 encoded characters.

STATE_VALID_2_AND_PADDINGback to summary
pack-priv 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

STATE_VALID_3back to summary
pack-priv static final int STATE_VALID_3

State in which we have gotten three valid non-padding base64 encoded characters.

Constructor Detail

Base64DecoderBaseback to summary
protected Base64DecoderBase()

Method Detail

decodeback to summary
public abstract int decode(byte[] resultBuffer, int resultOffset, int maxLength) throws IllegalArgumentException

Method that does actual decoding

decodeCompletelyback to summary
public byte[] decodeCompletely()

Method that can be called to completely decode content that this decoder has been initialized with.

endOfContentback to summary
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)
getByteAggregatorback to summary
public Stax2Util.ByteAggregator getByteAggregator()
hasDataback to summary
public final boolean hasData()

Method that can be called to check if this decoder is in has unflushed data ready to be returned.

reportInvalidCharback to summary
protected IllegalArgumentException reportInvalidChar(char ch, int bindex) throws IllegalArgumentException
reportInvalidCharback to summary
protected IllegalArgumentException reportInvalidChar(char ch, int bindex, String msg) throws IllegalArgumentException
Parameters
bindex:int

Relative index within base64 character unit; between 0 and 3 (as unit has exactly 4 characters)