Class MXSerializer


  • public class MXSerializer
    extends java.lang.Object
    Implementation of XmlSerializer interface from XmlPull V1 API. This implementation is optimzied for performance and low memory footprint.

    Implemented features:

    • FEATURE_NAMES_INTERNED - when enabled all returned names (namespaces, prefixes) will be interned and it is required that all names passed as arguments MUST be interned
    • FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE

    Implemented properties:

    • PROPERTY_SERIALIZER_INDENTATION
    • PROPERTY_SERIALIZER_LINE_SEPARATOR
    • Field Detail

      • FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE

        protected final java.lang.String FEATURE_SERIALIZER_ATTVALUE_USE_APOSTROPHE
        See Also:
        Constant Field Values
      • FEATURE_NAMES_INTERNED

        protected final java.lang.String FEATURE_NAMES_INTERNED
        See Also:
        Constant Field Values
      • PROPERTY_SERIALIZER_INDENTATION

        protected final java.lang.String PROPERTY_SERIALIZER_INDENTATION
        See Also:
        Constant Field Values
      • PROPERTY_SERIALIZER_LINE_SEPARATOR

        protected final java.lang.String PROPERTY_SERIALIZER_LINE_SEPARATOR
        See Also:
        Constant Field Values
      • PROPERTY_LOCATION

        protected static final java.lang.String PROPERTY_LOCATION
        See Also:
        Constant Field Values
      • namesInterned

        protected boolean namesInterned
      • attributeUseApostrophe

        protected boolean attributeUseApostrophe
      • indentationString

        protected java.lang.String indentationString
      • lineSeparator

        protected java.lang.String lineSeparator
      • location

        protected java.lang.String location
      • out

        protected java.io.Writer out
      • autoDeclaredPrefixes

        protected int autoDeclaredPrefixes
      • depth

        protected int depth
      • elNamespace

        protected java.lang.String[] elNamespace
      • elName

        protected java.lang.String[] elName
      • elNamespaceCount

        protected int[] elNamespaceCount
      • namespaceEnd

        protected int namespaceEnd
      • namespacePrefix

        protected java.lang.String[] namespacePrefix
      • namespaceUri

        protected java.lang.String[] namespaceUri
      • finished

        protected boolean finished
      • pastRoot

        protected boolean pastRoot
      • setPrefixCalled

        protected boolean setPrefixCalled
      • startTagIncomplete

        protected boolean startTagIncomplete
      • doIndent

        protected boolean doIndent
      • seenTag

        protected boolean seenTag
      • seenBracket

        protected boolean seenBracket
      • seenBracketBracket

        protected boolean seenBracketBracket
      • buf

        protected char[] buf
      • precomputedPrefixes

        protected static final java.lang.String[] precomputedPrefixes
      • offsetNewLine

        protected int offsetNewLine
      • indentationJump

        protected int indentationJump
      • indentationBuf

        protected char[] indentationBuf
      • maxIndentLevel

        protected int maxIndentLevel
      • writeLineSepartor

        protected boolean writeLineSepartor
      • writeIndentation

        protected boolean writeIndentation
    • Constructor Detail

      • MXSerializer

        public MXSerializer()
    • Method Detail

      • reset

        protected void reset()
      • ensureElementsCapacity

        protected void ensureElementsCapacity()
      • ensureNamespacesCapacity

        protected void ensureNamespacesCapacity()
      • setFeature

        public void setFeature​(java.lang.String name,
                               boolean state)
                        throws java.lang.IllegalArgumentException,
                               java.lang.IllegalStateException
        Throws:
        java.lang.IllegalArgumentException
        java.lang.IllegalStateException
      • getFeature

        public boolean getFeature​(java.lang.String name)
                           throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • rebuildIndentationBuf

        protected void rebuildIndentationBuf()
        For maximum efficiency when writing indents the required output is pre-computed This is internal function that recomputes buffer after user requested chnages.
      • writeIndent

        protected void writeIndent()
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • setProperty

        public void setProperty​(java.lang.String name,
                                java.lang.Object value)
                         throws java.lang.IllegalArgumentException,
                                java.lang.IllegalStateException
        Throws:
        java.lang.IllegalArgumentException
        java.lang.IllegalStateException
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
                                     throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • getWriter

        public java.io.Writer getWriter()
      • setOutput

        public void setOutput​(java.io.Writer writer)
      • setOutput

        public void setOutput​(java.io.OutputStream os,
                              java.lang.String encoding)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • startDocument

        public void startDocument​(java.lang.String encoding,
                                  java.lang.Boolean standalone)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • endDocument

        public void endDocument()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • setPrefix

        public void setPrefix​(java.lang.String prefix,
                              java.lang.String namespace)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • lookupOrDeclarePrefix

        protected java.lang.String lookupOrDeclarePrefix​(java.lang.String namespace)
      • getPrefix

        public java.lang.String getPrefix​(java.lang.String namespace,
                                          boolean generatePrefix)
      • getDepth

        public int getDepth()
      • getNamespace

        public java.lang.String getNamespace()
      • getName

        public java.lang.String getName()
      • startTag

        public MXSerializer startTag​(java.lang.String namespace,
                                     java.lang.String name)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • attribute

        public MXSerializer attribute​(java.lang.String namespace,
                                      java.lang.String name,
                                      java.lang.String value)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • closeStartTag

        protected void closeStartTag()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • endTag

        public MXSerializer endTag​(java.lang.String namespace,
                                   java.lang.String name)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • text

        public MXSerializer text​(java.lang.String text)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • text

        public MXSerializer text​(char[] buf,
                                 int start,
                                 int len)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • cdsect

        public void cdsect​(java.lang.String text)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • entityRef

        public void entityRef​(java.lang.String text)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • processingInstruction

        public void processingInstruction​(java.lang.String text)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • comment

        public void comment​(java.lang.String text)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • docdecl

        public void docdecl​(java.lang.String text)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • ignorableWhitespace

        public void ignorableWhitespace​(java.lang.String text)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • writeAttributeValue

        protected void writeAttributeValue​(java.lang.String value,
                                           java.io.Writer out)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeElementContent

        protected void writeElementContent​(java.lang.String text,
                                           java.io.Writer out)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeElementContent

        protected void writeElementContent​(char[] buf,
                                           int off,
                                           int len,
                                           java.io.Writer out)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • printable

        protected static java.lang.String printable​(java.lang.String s)
        simple utility method -- good for debugging
      • printable

        protected static java.lang.String printable​(char ch)