com.ctc.wstx.sw
Class EncodingXmlWriter

java.lang.Object
  extended by com.ctc.wstx.sw.XmlWriter
      extended by com.ctc.wstx.sw.EncodingXmlWriter
Direct Known Subclasses:
AsciiXmlWriter, ISOLatin1XmlWriter

public abstract class EncodingXmlWriter
extends XmlWriter

Intermediate base class used when outputting to streams that use an encoding that is compatible with 7-bit single-byte Ascii encoding. That means it can be used for UTF-8, ISO-Latin1 and pure Ascii.

Implementation notes:

Parts of surrogate handling are implemented here in the base class: storage for the first part of a split surrogate (only possible when character content is output split in multiple calls) is within base class. Also, simple checks for unmatched surrogate pairs are in writeAscii method, since it is the most convenient place to catch cases where a text segment ends with an unmatched surrogate pair half.


Field Summary
protected  java.io.OutputStream mOut
          Actual output stream to use for outputting encoded content as bytes.
protected  byte[] mOutputBuffer
           
protected  int mOutputPtr
           
protected  int mSurrogate
          In case a split surrogate pair is output (which can only successfully occur with either writeRaw or writeCharacters), the first part is temporarily stored within this member variable.
 
Fields inherited from class com.ctc.wstx.sw.XmlWriter
DEFAULT_QUOTE_CHAR, mAttrValueWriter, mAutoCloseOutput, mCheckContent, mCheckNames, mCheckStructure, mConfig, mEncoding, mFixContent, mLocPastChars, mLocRowNr, mLocRowStartOffset, mNsAware, mRawWrapper, mTextWrapper, mTextWriter, mXml11, SURR1_FIRST, SURR1_LAST, SURR2_FIRST, SURR2_LAST
 
Constructor Summary
EncodingXmlWriter(java.io.OutputStream out, WriterConfig cfg, java.lang.String encoding, boolean autoclose)
           
 
Method Summary
protected  int calcSurrogate(int secondSurr)
           
 void close()
          Method called to flush the buffer(s), and close the output sink (stream or writer).
 void flush()
           
protected  void flushBuffer()
           
protected  int getOutputPtr()
          This method is needed by the super class, to calculate hard byte/char offsets.
protected  java.io.OutputStream getOutputStream()
           
protected  java.io.Writer getWriter()
           
protected  void throwUnpairedSurrogate()
           
protected  void throwUnpairedSurrogate(int code)
           
protected  void writeAscii(byte b)
           
protected  void writeAscii(byte b1, byte b2)
           
protected  void writeAscii(java.lang.String str)
           
protected  int writeAsEntity(int c)
          Entity writing can be optimized quite nicely, since it only needs to output ascii characters.
 void writeAttribute(java.lang.String localName, char[] value, int offset, int len)
           
 void writeAttribute(java.lang.String localName, java.lang.String value)
           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)
 void writeAttribute(java.lang.String prefix, java.lang.String localName, char[] value, int offset, int len)
           
 void writeAttribute(java.lang.String prefix, java.lang.String localName, java.lang.String value)
           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)
protected abstract  void writeAttrValue(char[] value, int offset, int len)
           
protected abstract  void writeAttrValue(java.lang.String data)
           
 int writeCData(char[] cbuf, int offset, int len)
           
 int writeCData(java.lang.String data)
           
protected abstract  int writeCDataContent(char[] cbuf, int start, int len)
           
protected abstract  int writeCDataContent(java.lang.String data)
           
 void writeCDataEnd()
           
 void writeCDataStart()
           
 void writeCharacters(char[] cbuf, int offset, int len)
           
 void writeCharacters(java.lang.String data)
           
 int writeComment(java.lang.String data)
          Method that will try to output the content as specified.
protected abstract  int writeCommentContent(java.lang.String data)
           
 void writeCommentEnd()
           
 void writeCommentStart()
           
 void writeDTD(java.lang.String data)
          Older "legacy" output method for outputting DOCTYPE declaration.
 void writeDTD(java.lang.String rootName, java.lang.String systemId, java.lang.String publicId, java.lang.String internalSubset)
           
 void writeEndTag(java.lang.String localName)
           
 void writeEndTag(java.lang.String prefix, java.lang.String localName)
           
 void writeEntityReference(java.lang.String name)
           
protected  void writeName(java.lang.String name)
           
protected  void writeNameUnchecked(java.lang.String name)
           
 int writePI(java.lang.String target, java.lang.String data)
           
protected abstract  int writePIData(java.lang.String data)
           
 void writePIEnd()
           
 void writePIStart(java.lang.String target, boolean addSpace)
           
abstract  void writeRaw(char[] cbuf, int offset, int len)
           
abstract  void writeRaw(java.lang.String str, int offset, int len)
           
 void writeStartTagEmptyEnd()
           
 void writeStartTagEnd()
           
 void writeStartTagStart(java.lang.String localName)
           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)
 void writeStartTagStart(java.lang.String prefix, java.lang.String localName)
           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)
protected abstract  void writeTextContent(char[] cbuf, int start, int len)
           
protected abstract  void writeTextContent(java.lang.String data)
           
 void writeXmlDeclaration(java.lang.String version, java.lang.String encoding, java.lang.String standalone)
           
 
Methods inherited from class com.ctc.wstx.sw.XmlWriter
enableXml11, getAbsOffset, getColumn, getRow, reportNwfContent, reportNwfName, reportNwfName, throwInvalidChar, throwOutputError, throwOutputError, verifyNameValidity, wrapAsRawWriter, wrapAsTextWriter, writeRaw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mOut

protected final java.io.OutputStream mOut
Actual output stream to use for outputting encoded content as bytes.


mOutputBuffer

protected final byte[] mOutputBuffer

mOutputPtr

protected int mOutputPtr

mSurrogate

protected int mSurrogate
In case a split surrogate pair is output (which can only successfully occur with either writeRaw or writeCharacters), the first part is temporarily stored within this member variable.

Constructor Detail

EncodingXmlWriter

public EncodingXmlWriter(java.io.OutputStream out,
                         WriterConfig cfg,
                         java.lang.String encoding,
                         boolean autoclose)
                  throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getOutputPtr

protected int getOutputPtr()
This method is needed by the super class, to calculate hard byte/char offsets.

Specified by:
getOutputPtr in class XmlWriter

getOutputStream

protected final java.io.OutputStream getOutputStream()
Specified by:
getOutputStream in class XmlWriter
Returns:
Underlying OutputStream used for physical output, if the writer was constructed using one

getWriter

protected final java.io.Writer getWriter()
Specified by:
getWriter in class XmlWriter
Returns:
Underlying Writer used for physical output, if the writer was constructed with one, or one was created to be used with an OutputStream.

close

public void close()
           throws java.io.IOException
Description copied from class: XmlWriter
Method called to flush the buffer(s), and close the output sink (stream or writer).

Specified by:
close 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 abstract void writeRaw(char[] cbuf,
                              int offset,
                              int len)
                       throws java.io.IOException
Specified by:
writeRaw in class XmlWriter
Throws:
java.io.IOException

writeRaw

public abstract 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
Specified by:
writeCDataStart in class XmlWriter
Throws:
java.io.IOException

writeCDataEnd

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

writeCommentStart

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

writeCommentEnd

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

writePIStart

public final void writePIStart(java.lang.String target,
                               boolean addSpace)
                        throws java.io.IOException
Specified by:
writePIStart in class XmlWriter
Throws:
java.io.IOException

writePIEnd

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

writeCData

public int writeCData(java.lang.String data)
               throws java.io.IOException
Specified by:
writeCData in class XmlWriter
Parameters:
data - Contents of the CDATA section to write out
Returns:
offset of the (first) illegal content segment ("]]>") in passed content, if not in repairing mode; or -1 if none
Throws:
java.io.IOException

writeCData

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

writeCharacters

public final void writeCharacters(java.lang.String data)
                           throws java.io.IOException
Specified by:
writeCharacters in class XmlWriter
Throws:
java.io.IOException

writeCharacters

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

writeComment

public int writeComment(java.lang.String data)
                 throws java.io.IOException
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

writeDTD

public void writeDTD(java.lang.String data)
              throws java.io.IOException
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

writeDTD

public void writeDTD(java.lang.String 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(java.lang.String 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
Specified by:
writeXmlDeclaration in class XmlWriter
Throws:
java.io.IOException

writePI

public int writePI(java.lang.String 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

writeStartTagStart

public void writeStartTagStart(java.lang.String localName)
                        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

writeStartTagStart

public void writeStartTagStart(java.lang.String prefix,
                               java.lang.String localName)
                        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
Specified by:
writeStartTagEnd in class XmlWriter
Throws:
java.io.IOException

writeStartTagEmptyEnd

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

writeEndTag

public void writeEndTag(java.lang.String localName)
                 throws java.io.IOException
Specified by:
writeEndTag in class XmlWriter
Throws:
java.io.IOException

writeEndTag

public void writeEndTag(java.lang.String prefix,
                        java.lang.String localName)
                 throws java.io.IOException
Specified by:
writeEndTag in class XmlWriter
Throws:
java.io.IOException

writeAttribute

public void writeAttribute(java.lang.String localName,
                           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(java.lang.String localName,
                           char[] value,
                           int offset,
                           int len)
                    throws java.io.IOException,
                           javax.xml.stream.XMLStreamException
Specified by:
writeAttribute in class XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeAttribute

public void writeAttribute(java.lang.String prefix,
                           java.lang.String localName,
                           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(java.lang.String prefix,
                           java.lang.String localName,
                           char[] value,
                           int offset,
                           int len)
                    throws java.io.IOException,
                           javax.xml.stream.XMLStreamException
Specified by:
writeAttribute in class XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

flushBuffer

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

writeAscii

protected final void writeAscii(byte b)
                         throws java.io.IOException
Throws:
java.io.IOException

writeAscii

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

writeAscii

protected final void writeAscii(java.lang.String str)
                         throws java.io.IOException
Throws:
java.io.IOException

writeAsEntity

protected final int writeAsEntity(int c)
                           throws java.io.IOException
Entity writing can be optimized quite nicely, since it only needs to output ascii characters.

Returns:
New value of mOutputPtr
Throws:
java.io.IOException

writeName

protected final void writeName(java.lang.String name)
                        throws java.io.IOException,
                               javax.xml.stream.XMLStreamException
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeNameUnchecked

protected final void writeNameUnchecked(java.lang.String name)
                                 throws java.io.IOException
Throws:
java.io.IOException

calcSurrogate

protected final int calcSurrogate(int secondSurr)
                           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

writeAttrValue

protected abstract void writeAttrValue(java.lang.String data)
                                throws java.io.IOException
Throws:
java.io.IOException

writeAttrValue

protected abstract void writeAttrValue(char[] value,
                                       int offset,
                                       int len)
                                throws java.io.IOException
Throws:
java.io.IOException

writeCDataContent

protected abstract int writeCDataContent(java.lang.String data)
                                  throws java.io.IOException
Throws:
java.io.IOException

writeCDataContent

protected abstract int writeCDataContent(char[] cbuf,
                                         int start,
                                         int len)
                                  throws java.io.IOException
Throws:
java.io.IOException

writeCommentContent

protected abstract int writeCommentContent(java.lang.String data)
                                    throws java.io.IOException
Throws:
java.io.IOException

writePIData

protected abstract int writePIData(java.lang.String data)
                            throws java.io.IOException,
                                   javax.xml.stream.XMLStreamException
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeTextContent

protected abstract void writeTextContent(java.lang.String data)
                                  throws java.io.IOException
Throws:
java.io.IOException

writeTextContent

protected abstract void writeTextContent(char[] cbuf,
                                         int start,
                                         int len)
                                  throws java.io.IOException
Throws:
java.io.IOException