Class Base64DecoderBase

java.lang.Object
org.codehaus.stax2.ri.typed.Base64DecoderBase
Direct Known Subclasses:
CharArrayBase64Decoder, StringBase64Decoder

abstract class Base64DecoderBase extends 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
     
    (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
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract int
    decode(byte[] resultBuffer, int resultOffset, int maxLength)
    Method that does actual decoding
    byte[]
    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
    Method that can be called to check if this decoder is in has unflushed data ready to be returned.
    reportInvalidChar(char ch, int bindex)
     
    reportInvalidChar(char ch, int bindex, String msg)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • STATE_INITIAL

      static final int STATE_INITIAL
      Initial state is where we start, and where white space is accepted.
      See Also:
    • STATE_VALID_1

      static final int STATE_VALID_1
      State in which we have gotten one valid non-padding base64 encoded character
      See Also:
    • STATE_VALID_2

      static final int STATE_VALID_2
      State in which we have gotten two valid non-padding base64 encoded characters.
      See Also:
    • STATE_VALID_3

      static final int STATE_VALID_3
      State in which we have gotten three valid non-padding base64 encoded characters.
      See Also:
    • 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:
    • 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:
    • 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:
    • 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:
    • INT_SPACE

      static final int INT_SPACE
      See Also:
    • _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

  • 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

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