Class EncodingXmlWriter
- java.lang.Object
-
- com.ctc.wstx.sw.XmlWriter
-
- 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
writeAsciimethod, since it is the most convenient place to catch cases where a text segment ends with an unmatched surrogate pair half.
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]mOutputBufferprotected intmOutputPtrprotected intmSurrogateIn case a split surrogate pair is output (which can only successfully occur with eitherwriteRaworwriteCharacters), 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
Constructors Constructor Description EncodingXmlWriter(OutputStream out, WriterConfig cfg, String encoding, boolean autoclose)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected intcalcSurrogate(int secondSurr)voidclose(boolean forceRealClose)Method called to flush the buffer(s), and close the output sink (stream or writer) if enabled (auto-closing) or forced.voidflush()protected voidflushBuffer()protected intgetOutputPtr()This method is needed by the super class, to calculate hard byte/char offsets.protected OutputStreamgetOutputStream()protected WritergetWriter()protected voidthrowUnpairedSurrogate()protected voidthrowUnpairedSurrogate(int code)protected voidwriteAscii(byte b)protected voidwriteAscii(byte b1, byte b2)protected voidwriteAscii(String str)protected intwriteAsEntity(int c)Entity writing can be optimized quite nicely, since it only needs to output ascii characters.voidwriteAttribute(String localName, char[] value, int offset, int len)voidwriteAttribute(String localName, 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)voidwriteAttribute(String prefix, String localName, char[] value, int offset, int len)voidwriteAttribute(String prefix, String localName, 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 voidwriteAttrValue(char[] value, int offset, int len)protected abstract voidwriteAttrValue(String data)intwriteCData(char[] cbuf, int offset, int len)intwriteCData(String data)protected abstract intwriteCDataContent(char[] cbuf, int start, int len)protected abstract intwriteCDataContent(String data)voidwriteCDataEnd()voidwriteCDataStart()voidwriteCharacters(char[] cbuf, int offset, int len)voidwriteCharacters(String data)intwriteComment(String data)Method that will try to output the content as specified.protected abstract intwriteCommentContent(String data)voidwriteCommentEnd()voidwriteCommentStart()voidwriteDTD(String data)Older "legacy" output method for outputting DOCTYPE declaration.voidwriteDTD(String rootName, String systemId, String publicId, String internalSubset)voidwriteEndTag(String localName)voidwriteEndTag(String prefix, String localName)voidwriteEntityReference(String name)protected voidwriteName(String name)protected voidwriteNameUnchecked(String name)intwritePI(String target, String data)protected abstract intwritePIData(String data)voidwritePIEnd()voidwritePIStart(String target, boolean addSpace)abstract voidwriteRaw(char[] cbuf, int offset, int len)abstract voidwriteRaw(String str, int offset, int len)voidwriteRawAscii(char[] buf, int offset, int len)LikeXmlWriter.writeRaw(java.lang.String, int, int), but caller guarantees that the contents additionally are known to be in 7-bit ascii range.voidwriteStartTagEmptyEnd()voidwriteStartTagEnd()voidwriteStartTagStart(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)voidwriteStartTagStart(String prefix, 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 voidwriteTextContent(char[] cbuf, int start, int len)protected abstract voidwriteTextContent(String data)voidwriteTypedAttribute(String prefix, String localName, String nsURI, AsciiValueEncoder enc, XMLValidator validator, char[] copyBuffer)Method similar toXmlWriter.writeAttribute(String,String,char[],int,int)but where is known not to require escaping.voidwriteTypedAttribute(String prefix, String localName, AsciiValueEncoder enc)Method similar toXmlWriter.writeAttribute(String,String,char[],int,int)but where is known not to require escaping.voidwriteTypedAttribute(String localName, AsciiValueEncoder enc)Method similar toXmlWriter.writeAttribute(String,String,char[],int,int)but where is known not to require escaping.voidwriteTypedElement(AsciiValueEncoder enc)Non-validating version of typed write methodvoidwriteTypedElement(AsciiValueEncoder enc, XMLValidator validator, char[] copyBuffer)Validating version of typed write methodvoidwriteXmlDeclaration(String version, String encoding, String standalone)-
Methods inherited from class com.ctc.wstx.sw.XmlWriter
enableXml11, getAbsOffset, getColumn, getRow, handleInvalidChar, reportNwfContent, reportNwfName, reportNwfName, throwOutputError, throwOutputError, verifyNameValidity, wrapAsRawWriter, wrapAsTextWriter, writeRaw
-
-
-
-
Field Detail
-
mOutputBuffer
protected byte[] mOutputBuffer
-
mOutputPtr
protected int mOutputPtr
-
mSurrogate
protected int mSurrogate
In case a split surrogate pair is output (which can only successfully occur with eitherwriteRaworwriteCharacters), the first part is temporarily stored within this member variable.
-
-
Constructor Detail
-
EncodingXmlWriter
public EncodingXmlWriter(OutputStream out, WriterConfig cfg, String encoding, boolean autoclose) throws IOException
- Throws:
IOException
-
-
Method Detail
-
getOutputPtr
protected int getOutputPtr()
This method is needed by the super class, to calculate hard byte/char offsets.- Specified by:
getOutputPtrin classXmlWriter
-
getOutputStream
protected final OutputStream getOutputStream()
- Specified by:
getOutputStreamin classXmlWriter- Returns:
- Underlying OutputStream used for physical output, if the writer was constructed using one
-
getWriter
protected final Writer getWriter()
-
close
public void close(boolean forceRealClose) throws IOExceptionDescription copied from class:XmlWriterMethod called to flush the buffer(s), and close the output sink (stream or writer) if enabled (auto-closing) or forced.- Specified by:
closein classXmlWriter- Throws:
IOException
-
flush
public final void flush() throws IOException- Specified by:
flushin classXmlWriter- Throws:
IOException
-
writeRaw
public abstract void writeRaw(char[] cbuf, int offset, int len) throws IOException- Specified by:
writeRawin classXmlWriter- Throws:
IOException
-
writeRaw
public abstract void writeRaw(String str, int offset, int len) throws IOException
- Specified by:
writeRawin classXmlWriter- Throws:
IOException
-
writeCDataStart
public final void writeCDataStart() throws IOException- Specified by:
writeCDataStartin classXmlWriter- Throws:
IOException
-
writeCDataEnd
public final void writeCDataEnd() throws IOException- Specified by:
writeCDataEndin classXmlWriter- Throws:
IOException
-
writeCommentStart
public final void writeCommentStart() throws IOException- Specified by:
writeCommentStartin classXmlWriter- Throws:
IOException
-
writeCommentEnd
public final void writeCommentEnd() throws IOException- Specified by:
writeCommentEndin classXmlWriter- Throws:
IOException
-
writePIStart
public final void writePIStart(String target, boolean addSpace) throws IOException
- Specified by:
writePIStartin classXmlWriter- Throws:
IOException
-
writePIEnd
public final void writePIEnd() throws IOException- Specified by:
writePIEndin classXmlWriter- Throws:
IOException
-
writeCData
public int writeCData(String data) throws IOException
- Specified by:
writeCDatain classXmlWriter- Parameters:
data- Contents of the CDATA section to write out- Returns:
- offset of the (first) illegal content segment ("]]>") in passed content and not in repairing mode; or -1 if none or is repairing
- Throws:
IOException
-
writeCData
public int writeCData(char[] cbuf, int offset, int len) throws IOException- Specified by:
writeCDatain classXmlWriter- Throws:
IOException
-
writeCharacters
public final void writeCharacters(String data) throws IOException
- Specified by:
writeCharactersin classXmlWriter- Throws:
IOException
-
writeCharacters
public final void writeCharacters(char[] cbuf, int offset, int len) throws IOException- Specified by:
writeCharactersin classXmlWriter- Throws:
IOException
-
writeComment
public int writeComment(String data) throws 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:
writeCommentin classXmlWriter- Throws:
IOException
-
writeDTD
public void writeDTD(String data) throws IOException
Description copied from class:XmlWriterOlder "legacy" output method for outputting DOCTYPE declaration. Assumes that the passed-in String contains a complete DOCTYPE declaration properly quoted.- Specified by:
writeDTDin classXmlWriter- Throws:
IOException
-
writeDTD
public void writeDTD(String rootName, String systemId, String publicId, String internalSubset) throws IOException, XMLStreamException
- Specified by:
writeDTDin classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeEntityReference
public void writeEntityReference(String name) throws IOException, XMLStreamException
- Specified by:
writeEntityReferencein classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeXmlDeclaration
public void writeXmlDeclaration(String version, String encoding, String standalone) throws IOException
- Specified by:
writeXmlDeclarationin classXmlWriter- Throws:
IOException
-
writePI
public int writePI(String target, String data) throws IOException, XMLStreamException
- Specified by:
writePIin classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeStartTagStart
public void writeStartTagStart(String localName) throws IOException, XMLStreamException
Description copied from class:XmlWriterNote: 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:
writeStartTagStartin classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeStartTagStart
public void writeStartTagStart(String prefix, String localName) throws IOException, XMLStreamException
Description copied from class:XmlWriterNote: 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:
writeStartTagStartin classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeStartTagEnd
public void writeStartTagEnd() throws IOException- Specified by:
writeStartTagEndin classXmlWriter- Throws:
IOException
-
writeStartTagEmptyEnd
public void writeStartTagEmptyEnd() throws IOException- Specified by:
writeStartTagEmptyEndin classXmlWriter- Throws:
IOException
-
writeEndTag
public void writeEndTag(String localName) throws IOException
- Specified by:
writeEndTagin classXmlWriter- Throws:
IOException
-
writeEndTag
public void writeEndTag(String prefix, String localName) throws IOException
- Specified by:
writeEndTagin classXmlWriter- Throws:
IOException
-
writeAttribute
public void writeAttribute(String localName, String value) throws IOException, XMLStreamException
Description copied from class:XmlWriterNote: 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:
writeAttributein classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeAttribute
public void writeAttribute(String localName, char[] value, int offset, int len) throws IOException, XMLStreamException
- Specified by:
writeAttributein classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeAttribute
public void writeAttribute(String prefix, String localName, String value) throws IOException, XMLStreamException
Description copied from class:XmlWriterNote: 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:
writeAttributein classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeAttribute
public void writeAttribute(String prefix, String localName, char[] value, int offset, int len) throws IOException, XMLStreamException
- Specified by:
writeAttributein classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeTypedElement
public final void writeTypedElement(AsciiValueEncoder enc) throws IOException
Non-validating version of typed write method- Specified by:
writeTypedElementin classXmlWriter- Parameters:
enc- Encoder that will produce content- Throws:
IOException
-
writeTypedElement
public final void writeTypedElement(AsciiValueEncoder enc, XMLValidator validator, char[] copyBuffer) throws IOException, XMLStreamException
Validating version of typed write method- Specified by:
writeTypedElementin classXmlWriter- Parameters:
enc- Encoder that will produce contentvalidator- Validator to use for validating serialized textual content (can not be null)copyBuffer- Temporary buffer that writer can use for temporary copies as necessary- Throws:
IOExceptionXMLStreamException
-
writeTypedAttribute
public void writeTypedAttribute(String localName, AsciiValueEncoder enc) throws IOException, XMLStreamException
Description copied from class:XmlWriterMethod similar toXmlWriter.writeAttribute(String,String,char[],int,int)but where is known not to require escaping. No validation needs to be performed.- Specified by:
writeTypedAttributein classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeTypedAttribute
public void writeTypedAttribute(String prefix, String localName, AsciiValueEncoder enc) throws IOException, XMLStreamException
Description copied from class:XmlWriterMethod similar toXmlWriter.writeAttribute(String,String,char[],int,int)but where is known not to require escaping. No validation needs to be performed.- Specified by:
writeTypedAttributein classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeTypedAttribute
public void writeTypedAttribute(String prefix, String localName, String nsURI, AsciiValueEncoder enc, XMLValidator validator, char[] copyBuffer) throws IOException, XMLStreamException
Description copied from class:XmlWriterMethod similar toXmlWriter.writeAttribute(String,String,char[],int,int)but where is known not to require escaping. Validation of the attribute value must be done by calling given validator appropriately.- Specified by:
writeTypedAttributein classXmlWriter- Throws:
IOExceptionXMLStreamException
-
flushBuffer
protected final void flushBuffer() throws IOException- Throws:
IOException
-
writeAscii
protected final void writeAscii(byte b) throws IOException- Throws:
IOException
-
writeAscii
protected final void writeAscii(byte b1, byte b2) throws IOException- Throws:
IOException
-
writeAscii
protected final void writeAscii(String str) throws IOException
- Throws:
IOException
-
writeRawAscii
public final void writeRawAscii(char[] buf, int offset, int len) throws IOExceptionDescription copied from class:XmlWriterLikeXmlWriter.writeRaw(java.lang.String, int, int), but caller guarantees that the contents additionally are known to be in 7-bit ascii range.- Specified by:
writeRawAsciiin classXmlWriter- Throws:
IOException
-
writeAsEntity
protected final int writeAsEntity(int c) throws IOExceptionEntity writing can be optimized quite nicely, since it only needs to output ascii characters.- Returns:
- New value of
mOutputPtr - Throws:
IOException
-
writeName
protected final void writeName(String name) throws IOException, XMLStreamException
- Throws:
IOExceptionXMLStreamException
-
writeNameUnchecked
protected final void writeNameUnchecked(String name) throws IOException
- Throws:
IOException
-
calcSurrogate
protected final int calcSurrogate(int secondSurr) throws IOException- Throws:
IOException
-
throwUnpairedSurrogate
protected final void throwUnpairedSurrogate() throws IOException- Throws:
IOException
-
throwUnpairedSurrogate
protected final void throwUnpairedSurrogate(int code) throws IOException- Throws:
IOException
-
writeAttrValue
protected abstract void writeAttrValue(String data) throws IOException
- Throws:
IOException
-
writeAttrValue
protected abstract void writeAttrValue(char[] value, int offset, int len) throws IOException- Throws:
IOException
-
writeCDataContent
protected abstract int writeCDataContent(String data) throws IOException
- Throws:
IOException
-
writeCDataContent
protected abstract int writeCDataContent(char[] cbuf, int start, int len) throws IOException- Throws:
IOException
-
writeCommentContent
protected abstract int writeCommentContent(String data) throws IOException
- Throws:
IOException
-
writePIData
protected abstract int writePIData(String data) throws IOException, XMLStreamException
- Throws:
IOExceptionXMLStreamException
-
writeTextContent
protected abstract void writeTextContent(String data) throws IOException
- Throws:
IOException
-
writeTextContent
protected abstract void writeTextContent(char[] cbuf, int start, int len) throws IOException- Throws:
IOException
-
-