Class EncodingXmlWriter
- Direct Known Subclasses:
AsciiXmlWriter
,ISOLatin1XmlWriter
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
FieldsModifier and TypeFieldDescription(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final byte
(package private) static final int
Let's use a typical default to have a compromise between large enough chunks to output, and minimizing memory overhead.private final OutputStream
Actual output stream to use for outputting encoded content as bytes.protected byte[]
protected int
protected int
In case a split surrogate pair is output (which can only successfully occur with eitherwriteRaw
orwriteCharacters
), the first part is temporarily stored within this member variable.Fields inherited from class com.ctc.wstx.sw.XmlWriter
DEFAULT_QUOTE_CHAR, mAddSpaceAfterEmptyElem, mAttrValueWriter, mAutoCloseOutput, mCheckContent, mCheckNames, mCheckStructure, mConfig, mEncoding, mEscapeCR, mFixContent, mLocPastChars, mLocRowNr, mLocRowStartOffset, mNsAware, mRawWrapper, mTextWrapper, mTextWriter, mUseDoubleQuotesInXmlDecl, mXml11, SURR1_FIRST, SURR1_LAST, SURR2_FIRST, SURR2_LAST
-
Constructor Summary
ConstructorsConstructorDescriptionEncodingXmlWriter
(OutputStream out, WriterConfig cfg, String encoding, boolean autoclose) -
Method Summary
Modifier and TypeMethodDescriptionprotected final int
calcSurrogate
(int secondSurr) void
close
(boolean forceRealClose) Method called to flush the buffer(s), and close the output sink (stream or writer) if enabled (auto-closing) or forced.final void
flush()
protected final void
protected int
This method is needed by the super class, to calculate hard byte/char offsets.protected final OutputStream
protected final Writer
protected final void
protected final void
throwUnpairedSurrogate
(int code) protected final void
writeAscii
(byte b) protected final void
writeAscii
(byte b1, byte b2) protected final void
writeAscii
(String str) protected final int
writeAsEntity
(int c) Entity writing can be optimized quite nicely, since it only needs to output ascii characters.void
writeAttribute
(String localName, char[] value, int offset, int len) void
writeAttribute
(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)void
writeAttribute
(String prefix, String localName, char[] value, int offset, int len) void
writeAttribute
(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 void
writeAttrValue
(char[] value, int offset, int len) protected abstract void
writeAttrValue
(String data) int
writeCData
(char[] cbuf, int offset, int len) int
writeCData
(String data) protected abstract int
writeCDataContent
(char[] cbuf, int start, int len) protected abstract int
writeCDataContent
(String data) final void
final void
final void
writeCharacters
(char[] cbuf, int offset, int len) final void
writeCharacters
(String data) int
writeComment
(String data) Method that will try to output the content as specified.protected abstract int
writeCommentContent
(String data) final void
final void
void
Older "legacy" output method for outputting DOCTYPE declaration.void
void
writeEndTag
(String localName) void
writeEndTag
(String prefix, String localName) void
writeEntityReference
(String name) protected final void
protected final void
writeNameUnchecked
(String name) int
protected abstract int
writePIData
(String data) final void
final void
writePIStart
(String target, boolean addSpace) abstract void
writeRaw
(char[] cbuf, int offset, int len) abstract void
final void
writeRawAscii
(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.void
void
void
writeStartTagStart
(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
(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 void
writeTextContent
(char[] cbuf, int start, int len) protected abstract void
writeTextContent
(String data) void
writeTypedAttribute
(String prefix, String localName, String nsURI, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc, org.codehaus.stax2.validation.XMLValidator validator, char[] copyBuffer) Method similar toXmlWriter.writeAttribute(String,String,char[],int,int)
but where is known not to require escaping.void
writeTypedAttribute
(String prefix, String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) Method similar toXmlWriter.writeAttribute(String,String,char[],int,int)
but where is known not to require escaping.void
writeTypedAttribute
(String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) Method similar toXmlWriter.writeAttribute(String,String,char[],int,int)
but where is known not to require escaping.final void
writeTypedElement
(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) Non-validating version of typed write methodfinal void
writeTypedElement
(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc, org.codehaus.stax2.validation.XMLValidator validator, char[] copyBuffer) Validating version of typed write methodvoid
writeXmlDeclaration
(String version, String encoding, String standalone) Methods inherited from class com.ctc.wstx.sw.XmlWriter
enableXml11, getAbsOffset, getColumn, getRow, handleInvalidChar, reportNwfContent, reportNwfName, throwOutputError, throwOutputError, verifyNameValidity, wrapAsRawWriter, wrapAsTextWriter, writeRaw
-
Field Details
-
DEFAULT_BUFFER_SIZE
static final int DEFAULT_BUFFER_SIZELet's use a typical default to have a compromise between large enough chunks to output, and minimizing memory overhead. 4k should be close enough to a physical page to work out acceptably, without causing excessive (if temporary) memory usage.- See Also:
-
BYTE_SPACE
static final byte BYTE_SPACE- See Also:
-
BYTE_COLON
static final byte BYTE_COLON- See Also:
-
BYTE_SEMICOLON
static final byte BYTE_SEMICOLON- See Also:
-
BYTE_LBRACKET
static final byte BYTE_LBRACKET- See Also:
-
BYTE_RBRACKET
static final byte BYTE_RBRACKET- See Also:
-
BYTE_QMARK
static final byte BYTE_QMARK- See Also:
-
BYTE_EQ
static final byte BYTE_EQ- See Also:
-
BYTE_SLASH
static final byte BYTE_SLASH- See Also:
-
BYTE_HASH
static final byte BYTE_HASH- See Also:
-
BYTE_HYPHEN
static final byte BYTE_HYPHEN- See Also:
-
BYTE_LT
static final byte BYTE_LT- See Also:
-
BYTE_GT
static final byte BYTE_GT- See Also:
-
BYTE_AMP
static final byte BYTE_AMP- See Also:
-
BYTE_QUOT
static final byte BYTE_QUOT- See Also:
-
BYTE_APOS
static final byte BYTE_APOS- See Also:
-
BYTE_A
static final byte BYTE_A- See Also:
-
BYTE_G
static final byte BYTE_G- See Also:
-
BYTE_L
static final byte BYTE_L- See Also:
-
BYTE_M
static final byte BYTE_M- See Also:
-
BYTE_O
static final byte BYTE_O- See Also:
-
BYTE_P
static final byte BYTE_P- See Also:
-
BYTE_Q
static final byte BYTE_Q- See Also:
-
BYTE_S
static final byte BYTE_S- See Also:
-
BYTE_T
static final byte BYTE_T- See Also:
-
BYTE_U
static final byte BYTE_U- See Also:
-
BYTE_X
static final byte BYTE_X- See Also:
-
mOut
Actual output stream to use for outputting encoded content as bytes. -
mOutputBuffer
protected byte[] mOutputBuffer -
mOutputPtr
protected int mOutputPtr -
mSurrogate
protected int mSurrogateIn case a split surrogate pair is output (which can only successfully occur with eitherwriteRaw
orwriteCharacters
), the first part is temporarily stored within this member variable.
-
-
Constructor Details
-
EncodingXmlWriter
public EncodingXmlWriter(OutputStream out, WriterConfig cfg, String encoding, boolean autoclose) throws IOException - Throws:
IOException
-
-
Method Details
-
getOutputPtr
protected int getOutputPtr()This method is needed by the super class, to calculate hard byte/char offsets.- Specified by:
getOutputPtr
in classXmlWriter
-
getOutputStream
- Specified by:
getOutputStream
in classXmlWriter
- Returns:
- Underlying OutputStream used for physical output, if the writer was constructed using one
-
getWriter
-
close
Description copied from class:XmlWriter
Method called to flush the buffer(s), and close the output sink (stream or writer) if enabled (auto-closing) or forced.- Specified by:
close
in classXmlWriter
- Throws:
IOException
-
flush
- Specified by:
flush
in classXmlWriter
- Throws:
IOException
-
writeRaw
- Specified by:
writeRaw
in classXmlWriter
- Throws:
IOException
-
writeRaw
- Specified by:
writeRaw
in classXmlWriter
- Throws:
IOException
-
writeCDataStart
- Specified by:
writeCDataStart
in classXmlWriter
- Throws:
IOException
-
writeCDataEnd
- Specified by:
writeCDataEnd
in classXmlWriter
- Throws:
IOException
-
writeCommentStart
- Specified by:
writeCommentStart
in classXmlWriter
- Throws:
IOException
-
writeCommentEnd
- Specified by:
writeCommentEnd
in classXmlWriter
- Throws:
IOException
-
writePIStart
- Specified by:
writePIStart
in classXmlWriter
- Throws:
IOException
-
writePIEnd
- Specified by:
writePIEnd
in classXmlWriter
- Throws:
IOException
-
writeCData
- Specified by:
writeCData
in 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
- Specified by:
writeCData
in classXmlWriter
- Throws:
IOException
-
writeCharacters
- Specified by:
writeCharacters
in classXmlWriter
- Throws:
IOException
-
writeCharacters
- Specified by:
writeCharacters
in classXmlWriter
- Throws:
IOException
-
writeComment
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 classXmlWriter
- Throws:
IOException
-
writeDTD
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 classXmlWriter
- Throws:
IOException
-
writeDTD
public void writeDTD(String rootName, String systemId, String publicId, String internalSubset) throws IOException, XMLStreamException - Specified by:
writeDTD
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeEntityReference
- Specified by:
writeEntityReference
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeXmlDeclaration
public void writeXmlDeclaration(String version, String encoding, String standalone) throws IOException - Specified by:
writeXmlDeclaration
in classXmlWriter
- Throws:
IOException
-
writePI
- Specified by:
writePI
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeStartTagStart
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 classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeStartTagStart
public void writeStartTagStart(String prefix, String localName) throws IOException, 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 classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeStartTagEnd
- Specified by:
writeStartTagEnd
in classXmlWriter
- Throws:
IOException
-
writeStartTagEmptyEnd
- Specified by:
writeStartTagEmptyEnd
in classXmlWriter
- Throws:
IOException
-
writeEndTag
- Specified by:
writeEndTag
in classXmlWriter
- Throws:
IOException
-
writeEndTag
- Specified by:
writeEndTag
in classXmlWriter
- Throws:
IOException
-
writeAttribute
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 classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeAttribute
public void writeAttribute(String localName, char[] value, int offset, int len) throws IOException, XMLStreamException - Specified by:
writeAttribute
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeAttribute
public void writeAttribute(String prefix, String localName, String value) throws IOException, 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 classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeAttribute
public void writeAttribute(String prefix, String localName, char[] value, int offset, int len) throws IOException, XMLStreamException - Specified by:
writeAttribute
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeTypedElement
public final void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws IOException Non-validating version of typed write method- Specified by:
writeTypedElement
in classXmlWriter
- Parameters:
enc
- Encoder that will produce content- Throws:
IOException
-
writeTypedElement
public final void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc, org.codehaus.stax2.validation.XMLValidator validator, char[] copyBuffer) throws IOException, XMLStreamException Validating version of typed write method- Specified by:
writeTypedElement
in 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:
IOException
XMLStreamException
-
writeTypedAttribute
public void writeTypedAttribute(String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws IOException, XMLStreamException Description copied from class:XmlWriter
Method similar toXmlWriter.writeAttribute(String,String,char[],int,int)
but where is known not to require escaping. No validation needs to be performed.- Specified by:
writeTypedAttribute
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeTypedAttribute
public void writeTypedAttribute(String prefix, String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws IOException, XMLStreamException Description copied from class:XmlWriter
Method similar toXmlWriter.writeAttribute(String,String,char[],int,int)
but where is known not to require escaping. No validation needs to be performed.- Specified by:
writeTypedAttribute
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeTypedAttribute
public void writeTypedAttribute(String prefix, String localName, String nsURI, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc, org.codehaus.stax2.validation.XMLValidator validator, char[] copyBuffer) throws IOException, XMLStreamException Description copied from class:XmlWriter
Method 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:
writeTypedAttribute
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
flushBuffer
- Throws:
IOException
-
writeAscii
- Throws:
IOException
-
writeAscii
- Throws:
IOException
-
writeAscii
- Throws:
IOException
-
writeRawAscii
Description copied from class:XmlWriter
LikeXmlWriter.writeRaw(java.lang.String, int, int)
, but caller guarantees that the contents additionally are known to be in 7-bit ascii range.- Specified by:
writeRawAscii
in classXmlWriter
- Throws:
IOException
-
writeAsEntity
Entity writing can be optimized quite nicely, since it only needs to output ascii characters.- Returns:
- New value of
mOutputPtr
- Throws:
IOException
-
writeName
- Throws:
IOException
XMLStreamException
-
writeNameUnchecked
- Throws:
IOException
-
calcSurrogate
- Throws:
IOException
-
throwUnpairedSurrogate
- Throws:
IOException
-
throwUnpairedSurrogate
- Throws:
IOException
-
writeAttrValue
- Throws:
IOException
-
writeAttrValue
- Throws:
IOException
-
writeCDataContent
- Throws:
IOException
-
writeCDataContent
- Throws:
IOException
-
writeCommentContent
- Throws:
IOException
-
writePIData
- Throws:
IOException
XMLStreamException
-
writeTextContent
- Throws:
IOException
-
writeTextContent
- Throws:
IOException
-