Class ByteXmlWriter

  • Direct Known Subclasses:
    SingleByteXmlWriter, Utf8XmlWriter

    public abstract class ByteXmlWriter
    extends XmlWriter
    This abstract base class (partial implementation of XmlWriter) is used if the destination is byte-based OutputStream.

    Further, all existing implementations are for encodings that are 7-bit ascii compatible. This is important since this means that marker and separator characters are identical independent of actual encoding. This would not hold if support for encodings like EBCDIC were supported using this class.

    • Field Detail

      • 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
      • DEFAULT_COPY_BUFFER_SIZE

        static final int DEFAULT_COPY_BUFFER_SIZE
        Default intermediate copy buffer size, to be used for efficient access to String content. Smaller, since it's in characters, plus will not be used for actual write operations
        See Also:
        Constant Field Values
      • SMALL_WRITE

        static final int SMALL_WRITE
        Let's try avoid short writes, since some output streams have high per-call penalty (like network streams).
        See Also:
        Constant Field Values
      • BYTES_CDATA_START

        static final byte[] BYTES_CDATA_START
      • BYTES_CDATA_END

        static final byte[] BYTES_CDATA_END
      • BYTES_COMMENT_START

        static final byte[] BYTES_COMMENT_START
      • BYTES_COMMENT_END

        static final byte[] BYTES_COMMENT_END
      • BYTES_XMLDECL_START

        static final byte[] BYTES_XMLDECL_START
      • BYTES_XMLDECL_ENCODING

        static final byte[] BYTES_XMLDECL_ENCODING
      • BYTES_XMLDECL_STANDALONE

        static final byte[] BYTES_XMLDECL_STANDALONE
      • _out

        protected java.io.OutputStream _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 byte[] _outputBuffer
      • _outputPtr

        protected int _outputPtr
      • _outputBufferLen

        protected final int _outputBufferLen
      • _surrogate

        protected int _surrogate
        In case a split surrogate pair is output (which can occur for only some of the methods, possibly depending on encoding), the first part is temporarily stored within this member variable.
      • _charTypes

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

    • Method Detail

      • constructName

        public final WName constructName​(java.lang.String localName)
                                  throws javax.xml.stream.XMLStreamException
        Specified by:
        constructName in class XmlWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • constructName

        public WName constructName​(java.lang.String prefix,
                                   java.lang.String localName)
                            throws javax.xml.stream.XMLStreamException
        Specified by:
        constructName in class XmlWriter
        Throws:
        javax.xml.stream.XMLStreamException
      • doConstructName

        protected abstract WName doConstructName​(java.lang.String localName)
                                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • doConstructName

        protected abstract WName doConstructName​(java.lang.String prefix,
                                                 java.lang.String localName)
                                          throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • verifyNameComponent

        protected void verifyNameComponent​(java.lang.String part)
                                    throws javax.xml.stream.XMLStreamException
        Method used to verify that a name component (prefix, local name) is a legal as per xml 1.0 specification.
        Throws:
        java.lang.IllegalArgumentException - If name component contains an invalid (non-name; or for the initial characters, non-name-first) character.
        javax.xml.stream.XMLStreamException
      • outputSurrogates

        protected abstract void outputSurrogates​(int surr1,
                                                 int surr2)
                                          throws java.io.IOException,
                                                 javax.xml.stream.XMLStreamException
        Method called to output a composite character, result of combining 2 surrogate characters.
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • output2ByteChar

        protected abstract void output2ByteChar​(int ch)
                                         throws java.io.IOException,
                                                javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • outputStrictMultiByteChar

        protected abstract int outputStrictMultiByteChar​(int ch,
                                                         char[] cbuf,
                                                         int inputOffset,
                                                         int inputLen)
                                                  throws java.io.IOException,
                                                         javax.xml.stream.XMLStreamException
        Method called to output a character beyond basic 1- or 2-byte encoding (code 0x0800 and above), without being able to use character entities
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • outputMultiByteChar

        protected abstract int outputMultiByteChar​(int ch,
                                                   char[] cbuf,
                                                   int inputOffset,
                                                   int inputLen)
                                            throws java.io.IOException,
                                                   javax.xml.stream.XMLStreamException
        Method called to output a character beyond basic 1- or 2-byte encoding (code 0x0800 and above); possibly using character entities, if necessary
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • _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 final void writeRaw​(java.lang.String text,
                                   int offset,
                                   int len)
                            throws java.io.IOException,
                                   javax.xml.stream.XMLStreamException
        Specified by:
        writeRaw in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeRaw

        public abstract void writeRaw​(char[] cbuf,
                                      int offset,
                                      int len)
                               throws java.io.IOException,
                                      javax.xml.stream.XMLStreamException
        This method is heavily encoding-dependant, so it needs to be deferred to sub-classes
        Specified by:
        writeRaw in class XmlWriter
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeStartTagStart

        public final 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 final 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 final 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 final 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 final void writeAttribute​(WName name,
                                         char[] vbuf,
                                         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
      • fastWriteAttrValue

        protected final int fastWriteAttrValue​(char[] vbuf,
                                               int offset,
                                               int len,
                                               byte[] bbuf,
                                               int ptr)
                                        throws java.io.IOException,
                                               javax.xml.stream.XMLStreamException
        Method called to copy given attribute value, when it's known that it will completely fit in the output buffer without further checks
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeAttrValue

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

        protected final void writeLongAttribute​(WName name,
                                                java.lang.String value,
                                                int vlen)
                                         throws java.io.IOException,
                                                javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeName

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

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

        protected final void writeName​(WName name,
                                       byte postChar)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeAttrNameEqQ

        private final void writeAttrNameEqQ​(WName name)
                                     throws java.io.IOException,
                                            javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • 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

        protected 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 final 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
      • longWriteCharacters

        private final void longWriteCharacters​(java.lang.String text)
                                        throws java.io.IOException,
                                               javax.xml.stream.XMLStreamException
        Throws:
        java.io.IOException
        javax.xml.stream.XMLStreamException
      • writeCharacters

        public final 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
      • writeSplitCharacters

        private final void writeSplitCharacters​(char[] cbuf,
                                                int offset,
                                                int len)
                                         throws java.io.IOException,
                                                javax.xml.stream.XMLStreamException
        This method is called when it is possible that the output may cross the output buffer boundary. Because of this, code has to add more boundary checks.
        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
      • 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

        protected int writeCommentContents​(char[] cbuf,
                                           int offset,
                                           int len)
                                    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
      • writePIData

        protected int writePIData​(char[] cbuf,
                                  int offset,
                                  int len)
                           throws java.io.IOException,
                                  javax.xml.stream.XMLStreamException
        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
      • 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
      • writeSpace

        public final 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
      • 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
      • writeCDataStart

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

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

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

        protected final void writeCommentEnd()
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • writeRaw

        protected final void writeRaw​(byte b)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeRaw

        protected final void writeRaw​(byte b1,
                                      byte b2)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeRaw

        protected final void writeRaw​(byte[] buf)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeRaw

        protected final void writeRaw​(byte[] buf,
                                      int offset,
                                      int len)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • throwUnpairedSurrogate

        protected final void throwUnpairedSurrogate()
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • throwUnpairedSurrogate

        protected final void throwUnpairedSurrogate​(int code)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • flushBuffer

        protected final void flushBuffer()
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeAsEntity

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

        protected final int calcSurrogate​(int surr1,
                                          int surr2,
                                          java.lang.String context)
                                   throws javax.xml.stream.XMLStreamException
        Throws:
        javax.xml.stream.XMLStreamException
      • getAscii

        protected static final byte[] getAscii​(java.lang.String str)
      • getAscii

        protected static final void getAscii​(java.lang.String str,
                                             byte[] result)
      • getAscii

        protected static final void getAscii​(java.lang.String str,
                                             byte[] result,
                                             int offset)