Class Encoder

  • All Implemented Interfaces:
    FastInfosetSerializer, ContentHandler, DTDHandler, EntityResolver, ErrorHandler
    Direct Known Subclasses:
    DOMDocumentSerializer, SAXDocumentSerializer, StAXDocumentSerializer

    public abstract class Encoder
    extends DefaultHandler
    implements FastInfosetSerializer
    Abstract encoder for developing concrete encoders. Concrete implementations extending Encoder will utilize methods on Encoder to encode XML infoset according to the Fast Infoset standard. It is the responsibility of the concrete implementation to ensure that methods are invoked in the correct order to produce a valid fast infoset document.

    This class extends org.sax.xml.DefaultHandler so that concrete SAX implementations can be used with javax.xml.parsers.SAXParser and the parse methods that take org.sax.xml.DefaultHandler as a parameter.

    Buffering of octets that are written to an OutputStream is supported in a similar manner to a BufferedOutputStream. Combining buffering with encoding enables better performance.

    More than one fast infoset document may be encoded to the OutputStream.

    • Field Detail

      • CHARACTER_ENCODING_SCHEME_SYSTEM_PROPERTY

        public static final String CHARACTER_ENCODING_SCHEME_SYSTEM_PROPERTY
        Character encoding scheme system property for the encoding of content and attribute values.
        See Also:
        Constant Field Values
      • _characterEncodingSchemeSystemDefault

        protected static final String _characterEncodingSchemeSystemDefault
        Default character encoding scheme system property for the encoding of content and attribute values.
      • _terminate

        protected boolean _terminate
        True if terminatation of an information item is required
      • _b

        protected int _b
        The current octet that is to be written.
      • _s

        protected OutputStream _s
        The OutputStream that the encoded XML infoset (the fast infoset document) is written to.
      • _charBuffer

        protected char[] _charBuffer
        The internal buffer of characters used for the UTF-8 or UTF-16 encoding of characters.
      • _octetBuffer

        protected byte[] _octetBuffer
        The internal buffer of bytes.
      • _octetBufferIndex

        protected int _octetBufferIndex
        The current position in the internal buffer.
      • _markIndex

        protected int _markIndex
        The current mark in the internal buffer.

        If the value of the mark is < 0 then the mark is not set.

      • minAttributeValueSize

        protected int minAttributeValueSize
        The minimum size of [normalized value] of Attribute Information Items that will be indexed.
      • maxAttributeValueSize

        protected int maxAttributeValueSize
        The maximum size of [normalized value] of Attribute Information Items that will be indexed.
      • attributeValueMapTotalCharactersConstraint

        protected int attributeValueMapTotalCharactersConstraint
        The limit on the size of indexed Map for attribute values Limit is measured in characters number
      • minCharacterContentChunkSize

        protected int minCharacterContentChunkSize
        The minimum size of character content chunks of Character Information Items or Comment Information Items that will be indexed.
      • maxCharacterContentChunkSize

        protected int maxCharacterContentChunkSize
        The maximum size of character content chunks of Character Information Items or Comment Information Items that will be indexed.
      • characterContentChunkMapTotalCharactersConstraint

        protected int characterContentChunkMapTotalCharactersConstraint
        The limit on the size of indexed Map for character content chunks Limit is measured in characters number
    • Constructor Detail

      • Encoder

        protected Encoder()
        Default constructor for the Encoder.
      • Encoder

        protected Encoder​(boolean useLocalNameAsKeyForQualifiedNameLookup)
    • Method Detail

      • setCharacterEncodingScheme

        public final void setCharacterEncodingScheme​(String characterEncodingScheme)
        Sets the character encoding scheme. The character encoding can be either UTF-8 or UTF-16BE for the the encoding of chunks of CIIs, the [normalized value] property of attribute information items, comment information items and processing instruction information items.
        Specified by:
        setCharacterEncodingScheme in interface FastInfosetSerializer
        Parameters:
        characterEncodingScheme - The set of registered algorithms.
      • getMinCharacterContentChunkSize

        public int getMinCharacterContentChunkSize()
        Gets the minimum size of character content chunks that will be indexed.
        Specified by:
        getMinCharacterContentChunkSize in interface FastInfosetSerializer
        Returns:
        The minimum character content chunk size.
      • setMinCharacterContentChunkSize

        public void setMinCharacterContentChunkSize​(int size)
        Sets the minimum size of character content chunks that will be indexed.
        Specified by:
        setMinCharacterContentChunkSize in interface FastInfosetSerializer
        Parameters:
        size - the minimum character content chunk size.
      • getMaxCharacterContentChunkSize

        public int getMaxCharacterContentChunkSize()
        Gets the maximum size of character content chunks that might be indexed.
        Specified by:
        getMaxCharacterContentChunkSize in interface FastInfosetSerializer
        Returns:
        The maximum character content chunk size.
      • setMaxCharacterContentChunkSize

        public void setMaxCharacterContentChunkSize​(int size)
        Sets the maximum size of character content chunks that might be indexed.
        Specified by:
        setMaxCharacterContentChunkSize in interface FastInfosetSerializer
        Parameters:
        size - the maximum character content chunk size.
      • getCharacterContentChunkMapMemoryLimit

        public int getCharacterContentChunkMapMemoryLimit()
        Gets the limit on the memory size, allocated for indexed character content chunks.
        Specified by:
        getCharacterContentChunkMapMemoryLimit in interface FastInfosetSerializer
        Returns:
        the limit on the memory size, allocated for indexed character content chunks.
      • setCharacterContentChunkMapMemoryLimit

        public void setCharacterContentChunkMapMemoryLimit​(int size)
        Sets the limit on the memory size, allocated for indexed character content chunks.
        Specified by:
        setCharacterContentChunkMapMemoryLimit in interface FastInfosetSerializer
        Parameters:
        size - the limit on the memory size, allocated for indexed character content chunks.
      • isCharacterContentChunkLengthMatchesLimit

        public boolean isCharacterContentChunkLengthMatchesLimit​(int length)
        Checks whether character content chunk (its length) matches length limit
        Parameters:
        length - the length of character content chunk is checking to be added to Map.
        Returns:
        whether character content chunk length matches limit
      • canAddCharacterContentToTable

        public boolean canAddCharacterContentToTable​(int length,
                                                     CharArrayIntMap map)
        Checks whether character content table has enough memory to store character content chunk with the given length
        Parameters:
        length - the length of character content chunk is checking to be added to Map.
        map - the custom CharArrayIntMap, which memory limits will be checked.
        Returns:
        whether character content map has enough memory
      • getMinAttributeValueSize

        public int getMinAttributeValueSize()
        Gets the minimum size of attribute values that will be indexed.
        Specified by:
        getMinAttributeValueSize in interface FastInfosetSerializer
        Returns:
        The minimum attribute values size.
      • setMinAttributeValueSize

        public void setMinAttributeValueSize​(int size)
        Sets the minimum size of attribute values that will be indexed.
        Specified by:
        setMinAttributeValueSize in interface FastInfosetSerializer
        Parameters:
        size - the minimum attribute values size.
      • getMaxAttributeValueSize

        public int getMaxAttributeValueSize()
        Gets the maximum size of attribute values that will be indexed.
        Specified by:
        getMaxAttributeValueSize in interface FastInfosetSerializer
        Returns:
        The maximum attribute values size.
      • setMaxAttributeValueSize

        public void setMaxAttributeValueSize​(int size)
        Sets the maximum size of attribute values that will be indexed.
        Specified by:
        setMaxAttributeValueSize in interface FastInfosetSerializer
        Parameters:
        size - the maximum attribute values size.
      • setAttributeValueMapMemoryLimit

        public void setAttributeValueMapMemoryLimit​(int size)
        Sets the limit on the memory size of Map of attribute values that will be indexed.
        Specified by:
        setAttributeValueMapMemoryLimit in interface FastInfosetSerializer
        Parameters:
        size - The attribute value size limit. Any value less that a length of size limit will be indexed.
      • getAttributeValueMapMemoryLimit

        public int getAttributeValueMapMemoryLimit()
        Gets the limit on the memory size of Map of attribute values that will be indexed.
        Specified by:
        getAttributeValueMapMemoryLimit in interface FastInfosetSerializer
        Returns:
        The attribute value size limit.
      • isAttributeValueLengthMatchesLimit

        public boolean isAttributeValueLengthMatchesLimit​(int length)
        Checks whether attribute value (its length) matches length limit
        Parameters:
        length - the length of attribute
        Returns:
        whether attribute value matches limit
      • canAddAttributeToTable

        public boolean canAddAttributeToTable​(int length)
        Checks whether attribute table has enough memory to store attribute value with the given length
        Parameters:
        length - the length of attribute value is checking to be added to Map.
        Returns:
        whether attribute map has enough memory
      • reset

        public void reset()
        Reset the encoder for reuse encoding another XML infoset.
        Specified by:
        reset in interface FastInfosetSerializer
      • setOutputStream

        public void setOutputStream​(OutputStream s)
        Set the OutputStream to encode the XML infoset to a fast infoset document.
        Specified by:
        setOutputStream in interface FastInfosetSerializer
        Parameters:
        s - the OutputStream where the fast infoset document is written to.
      • setVocabulary

        public void setVocabulary​(SerializerVocabulary vocabulary)
        Set the SerializerVocabulary to be used for encoding.
        Parameters:
        vocabulary - the vocabulary to be used for encoding.
      • encodeHeader

        protected final void encodeHeader​(boolean encodeXmlDecl)
                                   throws IOException
        Encode the header of a fast infoset document.
        Parameters:
        encodeXmlDecl - true if the XML declaration should be encoded.
        Throws:
        IOException - on error
      • encodeInitialVocabulary

        protected final void encodeInitialVocabulary()
                                              throws IOException
        Encode the initial vocabulary of a fast infoset document.
        Throws:
        IOException - on error
      • encodeDocumentTermination

        protected final void encodeDocumentTermination()
                                                throws IOException
        Encode the termination of the Document Information Item.
        Throws:
        IOException - on error
      • encodeElementTermination

        protected final void encodeElementTermination()
                                               throws IOException
        Encode the termination of an Element Information Item.
        Throws:
        IOException - on error
      • encodeTermination

        protected final void encodeTermination()
                                        throws IOException
        Encode a termination if required.
        Throws:
        IOException - on error
      • encodeNamespaceAttribute

        protected final void encodeNamespaceAttribute​(String prefix,
                                                      String uri)
                                               throws IOException
        Encode a Attribute Information Item that is a namespace declaration.
        Parameters:
        prefix - the prefix of the namespace declaration, if "" then there is no prefix for the namespace declaration.
        uri - the URI of the namespace declaration, if "" then there is no URI for the namespace declaration.
        Throws:
        IOException - on error
      • encodeCharacters

        protected final void encodeCharacters​(char[] ch,
                                              int offset,
                                              int length)
                                       throws IOException
        Encode a chunk of Character Information Items.
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        IOException - on error
        ArrayIndexOutOfBoundsException - on error
      • encodeCharactersNoClone

        protected final void encodeCharactersNoClone​(char[] ch,
                                                     int offset,
                                                     int length)
                                              throws IOException
        Encode a chunk of Character Information Items. If the array of characters is to be indexed (as determined by isCharacterContentChunkLengthMatchesLimit(int)) then the array is not cloned when adding the array to the vocabulary.
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        IOException - on error
        ArrayIndexOutOfBoundsException - on error
      • encodeNumericFourBitCharacters

        protected final void encodeNumericFourBitCharacters​(char[] ch,
                                                            int offset,
                                                            int length,
                                                            boolean addToTable)
                                                     throws FastInfosetException,
                                                            IOException
        Encode a chunk of Character Information Items using a numeric alphabet that results in the encoding of a character in 4 bits (or two characters per octet).
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        addToTable - if characters should be added to table.
        Throws:
        IOException - on error
        ArrayIndexOutOfBoundsException - on error
        FastInfosetException
      • encodeDateTimeFourBitCharacters

        protected final void encodeDateTimeFourBitCharacters​(char[] ch,
                                                             int offset,
                                                             int length,
                                                             boolean addToTable)
                                                      throws FastInfosetException,
                                                             IOException
        Encode a chunk of Character Information Items using a date-time alphabet that results in the encoding of a character in 4 bits (or two characters per octet).
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        addToTable - if characters should be added to table.
        Throws:
        FastInfosetException - on error
        IOException - on error
        ArrayIndexOutOfBoundsException - on error
      • encodeFourBitCharacters

        protected final void encodeFourBitCharacters​(int id,
                                                     int[] table,
                                                     char[] ch,
                                                     int offset,
                                                     int length,
                                                     boolean addToTable)
                                              throws FastInfosetException,
                                                     IOException
        Encode a chunk of Character Information Items using a restricted alphabet that results in the encoding of a character in 4 bits (or two characters per octet).
        Parameters:
        id - the restricted alphabet identifier.
        table - the table mapping characters to 4 bit values.
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        addToTable - if characters should be added to table.
        Throws:
        FastInfosetException - on error
        IOException - on error
        ArrayIndexOutOfBoundsException - on error
      • encodeAlphabetCharacters

        protected final void encodeAlphabetCharacters​(String alphabet,
                                                      char[] ch,
                                                      int offset,
                                                      int length,
                                                      boolean addToTable)
                                               throws FastInfosetException,
                                                      IOException
        Encode a chunk of Character Information Items using a restricted alphabet table.
        Parameters:
        alphabet - the alphabet defining the mapping between characters and integer values.
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        addToTable - if characters should be added to table
        Throws:
        ArrayIndexOutOfBoundsException - on error
        IOException - on error
        FastInfosetException - if the alphabet is not present in the vocabulary.
      • encodeProcessingInstruction

        protected final void encodeProcessingInstruction​(String target,
                                                         String data)
                                                  throws IOException
        Encode a Processing Instruction Information Item.
        Parameters:
        target - the target of the processing instruction.
        data - the data of the processing instruction.
        Throws:
        IOException - on error
      • encodeDocumentTypeDeclaration

        protected final void encodeDocumentTypeDeclaration​(String systemId,
                                                           String publicId)
                                                    throws IOException
        Encode a Document Type Declaration.
        Parameters:
        systemId - the system identifier of the external subset.
        publicId - the public identifier of the external subset.
        Throws:
        IOException - on error
      • encodeComment

        protected final void encodeComment​(char[] ch,
                                           int offset,
                                           int length)
                                    throws IOException
        Encode a Comment Information Item.
        Parameters:
        ch - the array of characters that is as comment.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        IOException - on error
        ArrayIndexOutOfBoundsException - on error
      • encodeCommentNoClone

        protected final void encodeCommentNoClone​(char[] ch,
                                                  int offset,
                                                  int length)
                                           throws IOException
        Encode a Comment Information Item.If the array of characters that is a comment is to be indexed (as determined by isCharacterContentChunkLengthMatchesLimit(int)) then the array is not cloned when adding the array to the vocabulary.
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        IOException - on error
        ArrayIndexOutOfBoundsException - on error
      • encodeLiteralElementQualifiedNameOnThirdBit

        protected final void encodeLiteralElementQualifiedNameOnThirdBit​(String namespaceURI,
                                                                         String prefix,
                                                                         String localName,
                                                                         LocalNameQualifiedNamesMap.Entry entry)
                                                                  throws IOException
        Encode a literal qualified name of an Element InforImplementation of clause C.18 of ITU-T Rec.maiton IX.891 | ISO/IEC 24824-1.ause C.18 of ITU-T Rec.X.891 | ISO/IEC 24824-1.
        Parameters:
        namespaceURI - the namespace URI of the qualified name.
        prefix - the prefix of the qualified name.
        Throws:
        IOException - localName the local name of the qualified name.
      • encodeLiteralAttributeQualifiedNameOnSecondBit

        protected final boolean encodeLiteralAttributeQualifiedNameOnSecondBit​(String namespaceURI,
                                                                               String prefix,
                                                                               String localName,
                                                                               LocalNameQualifiedNamesMap.Entry entry)
                                                                        throws IOException
        Encode a literal qualified name of an Attribute InforImplementation of clause C.17 of ITU-T Rec.maiton IX.891 | ISO/IEC 24824-1.ause C.17 of ITU-T Rec.X.891 | ISO/IEC 24824-1.
        Parameters:
        namespaceURI - the namespace URI of the qualified name.
        prefix - the prefix of the qualified name.
        localName - the local name of the qualified name.
        Returns:
        localName the local name of the qualified name.
        Throws:
        IOException - on error
      • encodeNonIdentifyingStringOnFirstBit

        protected final void encodeNonIdentifyingStringOnFirstBit​(String s,
                                                                  StringIntMap map,
                                                                  boolean addToTable,
                                                                  boolean mustBeAddedToTable)
                                                           throws IOException
        Encode a non identifying string on the first bit of an octet.Implementation of clause C.14 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        s - the string to encode
        map - the vocabulary table of strings to indexes.
        addToTable - true if the string could be added to the vocabulary table (if table has enough memory)
        mustBeAddedToTable - true if the string must be added to the vocabulary table (if not already present in the table).
        Throws:
        IOException - on error
      • encodeNonIdentifyingStringOnFirstBit

        protected final void encodeNonIdentifyingStringOnFirstBit​(String s,
                                                                  CharArrayIntMap map,
                                                                  boolean addToTable)
                                                           throws IOException
        Encode a non identifying string on the first bit of an octet.Implementation of clause C.14 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        s - the string to encode
        map - the vocabulary table of character arrays to indexes.
        addToTable - true if the string should be added to the vocabulary table (if not already present in the table).
        Throws:
        IOException - on error
      • encodeNonIdentifyingStringOnFirstBit

        protected final void encodeNonIdentifyingStringOnFirstBit​(char[] ch,
                                                                  int offset,
                                                                  int length,
                                                                  CharArrayIntMap map,
                                                                  boolean addToTable,
                                                                  boolean clone)
                                                           throws IOException
        Encode a non identifying string on the first bit of an octet.Implementation of clause C.14 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        map - the vocabulary table of character arrays to indexes.
        addToTable - true if the string should be added to the vocabulary table (if not already present in the table).
        clone - true if the array of characters should be cloned if added to the vocabulary table.
        Throws:
        IOException - on error
      • encodeNonIdentifyingStringOnFirstBit

        protected final void encodeNonIdentifyingStringOnFirstBit​(String URI,
                                                                  int id,
                                                                  Object data)
                                                           throws FastInfosetException,
                                                                  IOException
        Encode a non identifying string on the first bit of an octet as binary data using an encoding algorithm.Implementation of clause C.14 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        URI - the encoding algorithm URI. If the URI == null then the encoding algorithm identifier takes precendence.
        id - the encoding algorithm identifier.
        data - the data to be encoded using an encoding algorithm.
        Throws:
        EncodingAlgorithmException - if the encoding algorithm URI is not present in the vocabulary, or the encoding algorithm identifier is not with the required range.
        IOException - on error
        FastInfosetException
      • encodeAIIOctetAlgorithmData

        protected final void encodeAIIOctetAlgorithmData​(int id,
                                                         byte[] d,
                                                         int offset,
                                                         int length)
                                                  throws IOException
        Encode the [normalized value] of an Attribute Information Item using using an encoding algorithm.Implementation of clause C.14 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        id - the encoding algorithm identifier.
        d - the data, as an array of bytes, to be encoded.
        offset - the offset into the array of bytes.
        length - the length of bytes.
        Throws:
        IOException - on error
      • encodeAIIObjectAlgorithmData

        protected final void encodeAIIObjectAlgorithmData​(int id,
                                                          Object data,
                                                          EncodingAlgorithm ea)
                                                   throws FastInfosetException,
                                                          IOException
        Encode the [normalized value] of an Attribute Information Item using using an encoding algorithm.Implementation of clause C.14 of ITU-T Rec.X.891 | ISO/IEC 24824-1.
        Parameters:
        id - the encoding algorithm identifier.
        data - the data to be encoded using an encoding algorithm.
        ea - the encoding algorithm to use to encode the data into an array of bytes.
        Throws:
        FastInfosetException - on error
        IOException - on error
      • encodeAIIBuiltInAlgorithmData

        protected final void encodeAIIBuiltInAlgorithmData​(int id,
                                                           Object data,
                                                           int offset,
                                                           int length)
                                                    throws IOException
        Encode the [normalized value] of an Attribute Information Item using using a built in encoding algorithm.Implementation of clause C.14 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        id - the built in encoding algorithm identifier.
        data - the data to be encoded using an encoding algorithm. The data represents an array of items specified by the encoding algorithm identifier
        offset - the offset into the array of bytes.
        length - the length of bytes.
        Throws:
        IOException
      • encodeNonIdentifyingStringOnThirdBit

        protected final void encodeNonIdentifyingStringOnThirdBit​(char[] ch,
                                                                  int offset,
                                                                  int length,
                                                                  CharArrayIntMap map,
                                                                  boolean addToTable,
                                                                  boolean clone)
                                                           throws IOException
        Encode a non identifying string on the third bit of an octet.Implementation of clause C.15 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        map - the vocabulary table of character arrays to indexes.
        addToTable - true if the array of characters should be added to the vocabulary table (if not already present in the table).
        clone - true if the array of characters should be cloned if added to the vocabulary table.
        Throws:
        IOException - on error
      • encodeNonIdentifyingStringOnThirdBit

        protected final void encodeNonIdentifyingStringOnThirdBit​(String URI,
                                                                  int id,
                                                                  Object data)
                                                           throws FastInfosetException,
                                                                  IOException
        Encode a non identifying string on the third bit of an octet as binary data using an encoding algorithm.Implementation of clause C.15 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        URI - the encoding algorithm URI. If the URI == null then the encoding algorithm identifier takes precendence.
        id - the encoding algorithm identifier.
        data - the data to be encoded using an encoding algorithm.
        Throws:
        EncodingAlgorithmException - if the encoding algorithm URI is not present in the vocabulary, or the encoding algorithm identifier is not with the required range.
        IOException - on error
        FastInfosetException
      • encodeNonIdentifyingStringOnThirdBit

        protected final void encodeNonIdentifyingStringOnThirdBit​(String URI,
                                                                  int id,
                                                                  byte[] d,
                                                                  int offset,
                                                                  int length)
                                                           throws FastInfosetException,
                                                                  IOException
        Encode a non identifying string on the third bit of an octet as binary data using an encoding algorithm.Implementation of clause C.15 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        URI - the encoding algorithm URI. If the URI == null then the encoding algorithm identifier takes precendence.
        id - the encoding algorithm identifier.
        d - the data, as an array of bytes, to be encoded.
        offset - the offset into the array of bytes.
        length - the length of bytes.
        Throws:
        EncodingAlgorithmException - if the encoding algorithm URI is not present in the vocabulary.
        IOException - on error
        FastInfosetException
      • encodeCIIOctetAlgorithmData

        protected final void encodeCIIOctetAlgorithmData​(int id,
                                                         byte[] d,
                                                         int offset,
                                                         int length)
                                                  throws IOException
        Encode a chunk of Character Information Items using using an encoding algorithm.Implementation of clause C.15 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        id - the encoding algorithm identifier.
        d - the data, as an array of bytes, to be encoded.
        offset - the offset into the array of bytes.
        length - the length of bytes.
        Throws:
        IOException - on error
      • encodeCIIObjectAlgorithmData

        protected final void encodeCIIObjectAlgorithmData​(int id,
                                                          Object data,
                                                          EncodingAlgorithm ea)
                                                   throws FastInfosetException,
                                                          IOException
        Encode a chunk of Character Information Items using using an encoding algorithm.Implementation of clause C.15 of ITU-T Rec.X.891 | ISO/IEC 24824-1.
        Parameters:
        id - the encoding algorithm identifier.
        data - the data to be encoded using an encoding algorithm.
        ea - the encoding algorithm to use to encode the data into an array of bytes.
        Throws:
        FastInfosetException - on error
        IOException - on error
      • encodeCIIBuiltInAlgorithmData

        protected final void encodeCIIBuiltInAlgorithmData​(int id,
                                                           Object data,
                                                           int offset,
                                                           int length)
                                                    throws FastInfosetException,
                                                           IOException
        Encode a chunk of Character Information Items using using an encoding algorithm.Implementation of clause C.15 of ITU-T Rec.X.891 | ISO/IEC 24824-1.
        Parameters:
        id - the built in encoding algorithm identifier.
        data - the data to be encoded using an encoding algorithm. The data represents an array of items specified by the encoding algorithm identifier
        offset - the offset into the array of bytes.
        length - the length of bytes.
        Throws:
        FastInfosetException - on error
        IOException - on error
      • encodeCIIBuiltInAlgorithmDataAsCDATA

        protected final void encodeCIIBuiltInAlgorithmDataAsCDATA​(char[] ch,
                                                                  int offset,
                                                                  int length)
                                                           throws FastInfosetException,
                                                                  IOException
        Encode a chunk of Character Information Items using using the CDATA built in encoding algorithm.Implementation of clause C.15 of ITU-T Rec.X.891 | ISO/IEC 24824-1.
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        FastInfosetException - on error
        IOException - on error
      • encodeIdentifyingNonEmptyStringOnFirstBit

        protected final void encodeIdentifyingNonEmptyStringOnFirstBit​(String s,
                                                                       StringIntMap map)
                                                                throws IOException
        Encode a non empty identifying string on the first bit of an octet.Implementation of clause C.13 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        s - the identifying string.
        map - the vocabulary table to use to determin the index of the identifying string
        Throws:
        IOException - on error
      • encodeNonEmptyOctetStringOnSecondBit

        protected final void encodeNonEmptyOctetStringOnSecondBit​(String s)
                                                           throws IOException
        Encode a non empty string on the second bit of an octet using the UTF-8 encoding.Implementation of clause C.22 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        s - the string.
        Throws:
        IOException - on error
      • encodeNonZeroOctetStringLengthOnSecondBit

        protected final void encodeNonZeroOctetStringLengthOnSecondBit​(int length)
                                                                throws IOException
        Encode the length of a UTF-8 encoded string on the second bit of an octet.Implementation of clause C.22 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        length - the length to encode.
        Throws:
        IOException - on error
      • encodeNonEmptyCharacterStringOnFifthBit

        protected final void encodeNonEmptyCharacterStringOnFifthBit​(String s)
                                                              throws IOException
        Encode a non empty string on the fifth bit of an octet using the UTF-8 or UTF-16 encoding.Implementation of clause C.23 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        s - the string.
        Throws:
        IOException - on error
      • encodeNonEmptyCharacterStringOnFifthBit

        protected final void encodeNonEmptyCharacterStringOnFifthBit​(char[] ch,
                                                                     int offset,
                                                                     int length)
                                                              throws IOException
        Encode a non empty string on the fifth bit of an octet using the UTF-8 or UTF-16 encoding.Implementation of clause C.23 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        IOException - on error
      • encodeNonZeroOctetStringLengthOnFifthBit

        protected final void encodeNonZeroOctetStringLengthOnFifthBit​(int length)
                                                               throws IOException
        Encode the length of a UTF-8 or UTF-16 encoded string on the fifth bit of an octet.Implementation of clause C.23 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        length - the length to encode.
        Throws:
        IOException - on error
      • encodeNonEmptyCharacterStringOnSeventhBit

        protected final void encodeNonEmptyCharacterStringOnSeventhBit​(char[] ch,
                                                                       int offset,
                                                                       int length)
                                                                throws IOException
        Encode a non empty string on the seventh bit of an octet using the UTF-8 or UTF-16 encoding.Implementation of clause C.24 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        IOException - on error
      • encodeNonEmptyFourBitCharacterStringOnSeventhBit

        protected final void encodeNonEmptyFourBitCharacterStringOnSeventhBit​(int[] table,
                                                                              char[] ch,
                                                                              int offset,
                                                                              int length)
                                                                       throws FastInfosetException,
                                                                              IOException
        Encode a non empty string on the seventh bit of an octet using a restricted alphabet that results in the encoding of a character in 4 bits (or two characters per octet).Implementation of clause C.24 of ITU-T Rec.X.891 | ISO/IEC 24824-1.
        Parameters:
        table - the table mapping characters to 4 bit values.
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        FastInfosetException - on error
        IOException - on error
      • encodeNonEmptyNBitCharacterStringOnSeventhBit

        protected final void encodeNonEmptyNBitCharacterStringOnSeventhBit​(String alphabet,
                                                                           char[] ch,
                                                                           int offset,
                                                                           int length)
                                                                    throws FastInfosetException,
                                                                           IOException
        Encode a non empty string on the seventh bit of an octet using a restricted alphabet table.Implementation of clause C.24 of ITU-T Rec.X.891 | ISO/IEC 24824-1.
        Parameters:
        alphabet - the alphabet defining the mapping between characters and integer values.
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        FastInfosetException - on error
        IOException - on error
      • encodeNonZeroOctetStringLengthOnSenventhBit

        protected final void encodeNonZeroOctetStringLengthOnSenventhBit​(int length)
                                                                  throws IOException
        Encode the length of a encoded string on the seventh bit of an octet.Implementation of clause C.24 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        length - the length to encode.
        Throws:
        IOException - on error
      • encodeNonZeroIntegerOnSecondBitFirstBitOne

        protected final void encodeNonZeroIntegerOnSecondBitFirstBitOne​(int i)
                                                                 throws IOException
        Encode a non zero integer on the second bit of an octet, setting the first bit to 1.Implementation of clause C.24 of ITU-T Rec. X.891 | ISO/IEC 24824-1.

        The first bit of the first octet is set, as specified in clause C.13 of ITU-T Rec. X.891 | ISO/IEC 24824-1

        Parameters:
        i - The integer to encode, which is a member of the interval [0, 1048575]. In the specification the interval is [1, 1048576]
        Throws:
        IOException - on error
      • encodeNonZeroIntegerOnSecondBitFirstBitZero

        protected final void encodeNonZeroIntegerOnSecondBitFirstBitZero​(int i)
                                                                  throws IOException
        Encode a non zero integer on the second bit of an octet, setting the first bit to 0.Implementation of clause C.25 of ITU-T Rec. X.891 | ISO/IEC 24824-1.

        The first bit of the first octet is set, as specified in clause C.13 of ITU-T Rec. X.891 | ISO/IEC 24824-1

        Parameters:
        i - The integer to encode, which is a member of the interval [0, 1048575]. In the specification the interval is [1, 1048576]
        Throws:
        IOException - on error
      • encodeNonZeroIntegerOnThirdBit

        protected final void encodeNonZeroIntegerOnThirdBit​(int i)
                                                     throws IOException
        Encode a non zero integer on the third bit of an octet.Implementation of clause C.27 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        i - The integer to encode, which is a member of the interval [0, 1048575]. In the specification the interval is [1, 1048576]
        Throws:
        IOException - on error
      • encodeNonZeroIntegerOnFourthBit

        protected final void encodeNonZeroIntegerOnFourthBit​(int i)
                                                      throws IOException
        Encode a non zero integer on the fourth bit of an octet.Implementation of clause C.28 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
        Parameters:
        i - The integer to encode, which is a member of the interval [0, 1048575]. In the specification the interval is [1, 1048576]
        Throws:
        IOException - on error
      • encodeNonEmptyUTF8StringAsOctetString

        protected final void encodeNonEmptyUTF8StringAsOctetString​(int b,
                                                                   String s,
                                                                   int[] constants)
                                                            throws IOException
        Encode a non empty string using the UTF-8 encoding.
        Parameters:
        b - the current octet that is being written.
        s - the string to be UTF-8 encoded.
        constants - the array of constants to use when encoding to determin how the length of the UTF-8 encoded string is encoded.
        Throws:
        IOException - on error
      • encodeNonEmptyUTF8StringAsOctetString

        protected final void encodeNonEmptyUTF8StringAsOctetString​(int b,
                                                                   char[] ch,
                                                                   int offset,
                                                                   int length,
                                                                   int[] constants)
                                                            throws IOException
        Encode a non empty string using the UTF-8 encoding.
        Parameters:
        b - the current octet that is being written.
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters. how the length of the UTF-8 encoded string is encoded.
        constants - the array of constants to use when encoding to determin how the length of the UTF-8 encoded string is encoded.
        Throws:
        IOException
      • encodeNonZeroOctetStringLength

        protected final void encodeNonZeroOctetStringLength​(int b,
                                                            int length,
                                                            int[] constants)
                                                     throws IOException
        Encode the length of non empty UTF-8 encoded string.
        Parameters:
        b - the current octet that is being written.
        length - the length of the UTF-8 encoded string. how the length of the UTF-8 encoded string is encoded.
        constants - the array of constants to use when encoding to determin how the length of the UTF-8 encoded string is encoded.
        Throws:
        IOException - on error
      • encodeNonZeroInteger

        protected final void encodeNonZeroInteger​(int b,
                                                  int i,
                                                  int[] constants)
                                           throws IOException
        Encode a non zero integer.
        Parameters:
        b - the current octet that is being written.
        i - the non zero integer.
        constants - the array of constants to use when encoding to determin how the non zero integer is encoded.
        Throws:
        IOException - on error
      • mark

        protected final void mark()
        Mark the current position in the buffered stream.
      • resetMark

        protected final void resetMark()
        Reset the marked position in the buffered stream.
      • hasMark

        protected final boolean hasMark()
        Returns:
        true if the mark has been set, otherwise false if the mark has not been set.
      • write

        protected final void write​(int i)
                            throws IOException
        Write a byte to the buffered stream.
        Throws:
        IOException - on error
      • write

        protected final void write​(byte[] b,
                                   int length)
                            throws IOException
        Write an array of bytes to the buffered stream.
        Parameters:
        b - the array of bytes.
        length - the length of bytes.
        Throws:
        IOException - on error
      • write

        protected final void write​(byte[] b,
                                   int offset,
                                   int length)
                            throws IOException
        Write an array of bytes to the buffered stream.
        Parameters:
        b - the array of bytes.
        offset - the offset into the array of bytes.
        length - the length of bytes.
        Throws:
        IOException - on error
      • encodeUTF8String

        protected final int encodeUTF8String​(String s)
                                      throws IOException
        Encode a string using the UTF-8 encoding.
        Parameters:
        s - the string to encode.
        Throws:
        IOException - on error
      • encodeUTF8String

        protected final int encodeUTF8String​(char[] ch,
                                             int offset,
                                             int length)
                                      throws IOException
        Encode a string using the UTF-8 encoding.
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        IOException - on error
      • encodeUtf16String

        protected final int encodeUtf16String​(String s)
                                       throws IOException
        Encode a string using the UTF-16 encoding.
        Parameters:
        s - the string to encode.
        Throws:
        IOException - on error
      • encodeUtf16String

        protected final int encodeUtf16String​(char[] ch,
                                              int offset,
                                              int length)
                                       throws IOException
        Encode a string using the UTF-16 encoding.
        Parameters:
        ch - the array of characters.
        offset - the offset into the array of characters.
        length - the length of characters.
        Throws:
        IOException - on error
      • getPrefixFromQualifiedName

        public static String getPrefixFromQualifiedName​(String qName)
        Obtain the prefix from a qualified name.
        Parameters:
        qName - the qualified name
        Returns:
        the prefix, or "" if there is no prefix.
      • isWhiteSpace

        public static boolean isWhiteSpace​(char[] ch,
                                           int start,
                                           int length)
        Check if character array contains characters that are all white space.
        Parameters:
        ch - the character array
        start - the starting character index into the array to check from
        length - the number of characters to check
        Returns:
        true if all characters are white space, false otherwise
      • isWhiteSpace

        public static boolean isWhiteSpace​(String s)
        Check if a String contains characters that are all white space.
        Parameters:
        s - the string
        Returns:
        true if all characters are white space, false otherwise