Class CharXmlWriter


  • public final class CharXmlWriter
    extends XmlWriter
    This is the generic implementation of XmlWriter, used if the destination is a character based, like a Writer.
    • Field Detail

      • DEFAULT_SMALL_SIZE

        static final int DEFAULT_SMALL_SIZE
        This value determines a threshold to choose how much data do we want to buffer at minimum, before output. This is done since actual underlying writer may have significant per-call overhead, and if so, it is much cheaper to coalesce content. But on the other hand, this extra buffering has overhead of its own, so we'll try to find a sweet spot.
        See Also:
        Constant Field Values
      • DEFAULT_FULL_BUFFER_SIZE

        static final int DEFAULT_FULL_BUFFER_SIZE
        And this value determines size of the intermediate copy buffer to use.
        See Also:
        Constant Field Values
      • mSmallWriteSize

        protected final int mSmallWriteSize
        This is the threshold used to check what is considered a "small" write; small writes will be buffered until resulting size will be above the threshold.
      • _out

        protected java.io.Writer _out
        Actual Writer to use for outputting buffered data as appropriate. During active usage, remains as the writer initially set; set to null when this writer is closed.
      • _outputBuffer

        protected char[] _outputBuffer
      • _outputPtr

        protected int _outputPtr
      • _outputBufferLen

        protected final int _outputBufferLen
      • mEncHighChar

        private final int mEncHighChar
        First Unicode character (one with lowest value) after (and including) which character entities have to be used.
      • mTableCheckEnd

        private final int mTableCheckEnd
        First Unicode character that is NOT to be checked against static validity table. Usually the size of check table, but lower for some encodings (like ascii)
      • mCharTypes

        final XmlCharTypes mCharTypes
        Validation tables used for verifying validity (and need for quoting)
    • Constructor Detail

      • CharXmlWriter

        public CharXmlWriter​(WriterConfig cfg,
                             java.io.Writer out)
    • Method Detail

      • getHighestEncodable

        public int getHighestEncodable()
        Description copied from class: XmlWriter
        Method called by error reporting code, to figure out if a given character is encodable (without using character entities) with the current encoding or not.
        Specified by:
        getHighestEncodable in class XmlWriter
        Returns:
        Character code of the highest character that can be natively encoded.
      • constructName

        public WName constructName​(java.lang.String prefix,
                                   java.lang.String localName)
        Specified by:
        constructName in class XmlWriter
      • _closeTarget

        public void _closeTarget​(boolean doClose)
                          throws java.io.IOException
        Specified by:
        _closeTarget in class XmlWriter
        Throws:
        java.io.IOException
      • flush

        public final void flush()
                         throws java.io.IOException
        Specified by:
        flush in class XmlWriter
        Throws:
        java.io.IOException
      • writeRaw

        public void writeRaw​(char[] cbuf,
                             int offset,
                             int len)
                      throws java.io.IOException
        Specified by:
        writeRaw in class XmlWriter
        Throws:
        java.io.IOException
      • writeRaw

        public void writeRaw​(java.lang.String str,
                             int offset,
                             int len)
                      throws java.io.IOException
        Specified by:
        writeRaw in class XmlWriter
        Throws:
        java.io.IOException
      • writeCDataStart

        public final void writeCDataStart()
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCDataEnd

        public final void writeCDataEnd()
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCommentStart

        public final void writeCommentStart()
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCommentEnd

        public final void writeCommentEnd()
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • writeCData

        public int writeCData​(java.lang.String data)
                       throws java.io.IOException,
                              javax.xml.stream.XMLStreamException
        Specified by:
        writeCData in class XmlWriter
        Parameters:
        data - Contents of the CDATA section to write out
        Returns:
        -1 to indicate succesful write, or index of the problematic character in input (first ']' from "]]>" sequence, in non-fixing mode)
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeCData

        public int writeCData​(char[] cbuf,
                              int offset,
                              int len)
                       throws java.io.IOException,
                              javax.xml.stream.XMLStreamException
        Specified by:
        writeCData in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeCDataContents

        private int writeCDataContents​(char[] cbuf,
                                       int offset,
                                       int len)
                                throws java.io.IOException,
                                       javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeCharacters

        public void writeCharacters​(java.lang.String text)
                             throws java.io.IOException,
                                    javax.xml.stream.XMLStreamException
        Specified by:
        writeCharacters in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeCharacters

        public void writeCharacters​(char[] cbuf,
                                    int offset,
                                    int len)
                             throws java.io.IOException,
                                    javax.xml.stream.XMLStreamException
        Specified by:
        writeCharacters in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeSpace

        public void writeSpace​(java.lang.String data)
                        throws java.io.IOException,
                               javax.xml.stream.XMLStreamException
        Specified by:
        writeSpace in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeSpace

        public void writeSpace​(char[] cbuf,
                               int offset,
                               int len)
                        throws java.io.IOException,
                               javax.xml.stream.XMLStreamException
        Specified by:
        writeSpace in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeComment

        public int writeComment​(java.lang.String data)
                         throws java.io.IOException,
                                javax.xml.stream.XMLStreamException
        Method that will try to output the content as specified. If the content passed in has embedded "--" in it, it will either add an intervening space between consequtive hyphens (if content fixing is enabled), or return the offset of the first hyphen in multi-hyphen sequence.
        Specified by:
        writeComment in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeCommentContents

        private int writeCommentContents​(char[] cbuf,
                                         int offset,
                                         int len,
                                         boolean last)
                                  throws java.io.IOException,
                                         javax.xml.stream.XMLStreamException
        Note: the only way to fix comment contents is to inject a space to split up consequtive '--' (or '-' that ends a comment).
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeDTD

        public void writeDTD​(java.lang.String data)
                      throws java.io.IOException,
                             javax.xml.stream.XMLStreamException
        Description copied from class: XmlWriter
        Older "legacy" output method for outputting DOCTYPE declaration. Assumes that the passed-in String contains a complete DOCTYPE declaration properly quoted.
        Specified by:
        writeDTD in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeDTD

        public void writeDTD​(WName rootName,
                             java.lang.String systemId,
                             java.lang.String publicId,
                             java.lang.String internalSubset)
                      throws java.io.IOException,
                             javax.xml.stream.XMLStreamException
        Specified by:
        writeDTD in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeEntityReference

        public void writeEntityReference​(WName name)
                                  throws java.io.IOException,
                                         javax.xml.stream.XMLStreamException
        Specified by:
        writeEntityReference in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeXmlDeclaration

        public void writeXmlDeclaration​(java.lang.String version,
                                        java.lang.String encoding,
                                        java.lang.String standalone)
                                 throws java.io.IOException,
                                        javax.xml.stream.XMLStreamException
        Specified by:
        writeXmlDeclaration in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writePI

        public int writePI​(WName target,
                           java.lang.String data)
                    throws java.io.IOException,
                           javax.xml.stream.XMLStreamException
        Specified by:
        writePI in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writePIContents

        private int writePIContents​(char[] cbuf,
                                    int offset,
                                    int len)
                             throws java.io.IOException,
                                    javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeStartTagStart

        public void writeStartTagStart​(WName name)
                                throws java.io.IOException,
                                       javax.xml.stream.XMLStreamException
        Description copied from class: XmlWriter

        Note: can throw XMLStreamException, if name checking is enabled, and name is invalid (name check has to be in this writer, not caller, since it depends not only on xml limitations, but also on encoding limitations)

        Specified by:
        writeStartTagStart in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeStartTagEnd

        public void writeStartTagEnd()
                              throws java.io.IOException,
                                     javax.xml.stream.XMLStreamException
        Specified by:
        writeStartTagEnd in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeStartTagEmptyEnd

        public void writeStartTagEmptyEnd()
                                   throws java.io.IOException
        Specified by:
        writeStartTagEmptyEnd in class XmlWriter
        Throws:
        java.io.IOException
      • writeEndTag

        public void writeEndTag​(WName name)
                         throws java.io.IOException,
                                javax.xml.stream.XMLStreamException
        Specified by:
        writeEndTag in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeAttribute

        public void writeAttribute​(WName name,
                                   java.lang.String value)
                            throws java.io.IOException,
                                   javax.xml.stream.XMLStreamException
        Description copied from class: XmlWriter

        Note: can throw XMLStreamException, if name checking is enabled, and name is invalid (name check has to be in this writer, not caller, since it depends not only on xml limitations, but also on encoding limitations)

        Specified by:
        writeAttribute in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeAttribute

        public void writeAttribute​(WName name,
                                   char[] value,
                                   int offset,
                                   int vlen)
                            throws java.io.IOException,
                                   javax.xml.stream.XMLStreamException
        Specified by:
        writeAttribute in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeAttrValue

        private final void writeAttrValue​(java.lang.String value,
                                          int len)
                                   throws java.io.IOException,
                                          javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeAttrValue

        private final void writeAttrValue​(char[] cbuf,
                                          int offset,
                                          int len)
                                   throws java.io.IOException,
                                          javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeSplitAttrValue

        private final void writeSplitAttrValue​(char[] cbuf,
                                               int offset,
                                               int len)
                                        throws java.io.IOException,
                                               javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeTypedValue

        public void writeTypedValue​(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
                             throws java.io.IOException,
                                    javax.xml.stream.XMLStreamException
        Specified by:
        writeTypedValue in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeAttribute

        public final void writeAttribute​(WName name,
                                         org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
                                  throws java.io.IOException,
                                         javax.xml.stream.XMLStreamException
        Specified by:
        writeAttribute in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • flushBuffer

        private final void flushBuffer()
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeName

        protected final void writeName​(WName name)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • fastWriteRaw

        private final void fastWriteRaw​(char c)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • fastWriteRaw

        private final void fastWriteRaw​(char c1,
                                        char c2)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • fastWriteRaw

        private final void fastWriteRaw​(java.lang.String str)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • verifyCDataContent

        protected int verifyCDataContent​(java.lang.String content)
        Returns:
        Index at which a problem was found, if any; -1 if there's no problem.
      • verifyCDataContent

        protected int verifyCDataContent​(char[] c,
                                         int start,
                                         int end)
      • verifyCommentContent

        protected int verifyCommentContent​(java.lang.String content)
      • writeSegmentedCData

        protected void writeSegmentedCData​(java.lang.String content,
                                           int index)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSegmentedCData

        protected void writeSegmentedCData​(char[] c,
                                           int start,
                                           int len,
                                           int index)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSegmentedComment

        protected void writeSegmentedComment​(java.lang.String content,
                                             int index)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • writeAsEntity

        protected final void writeAsEntity​(int c)
                                    throws java.io.IOException
        Throws:
        java.io.IOException