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 intLet's use a typical default to have a compromise between large enough chunks to output, and minimizing memory overhead.private final OutputStreamActual output stream to use for outputting encoded content as bytes.protected byte[]protected intprotected intIn 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 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 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.final voidflush()protected final voidprotected intThis method is needed by the super class, to calculate hard byte/char offsets.protected final OutputStreamprotected final Writerprotected final voidprotected final voidthrowUnpairedSurrogate(int code) protected final voidwriteAscii(byte b) protected final voidwriteAscii(byte b1, byte b2) protected final voidwriteAscii(String str) protected final 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) final voidfinal voidfinal voidwriteCharacters(char[] cbuf, int offset, int len) final voidwriteCharacters(String data) intwriteComment(String data) Method that will try to output the content as specified.protected abstract intwriteCommentContent(String data) final voidfinal voidvoidOlder "legacy" output method for outputting DOCTYPE declaration.voidvoidwriteEndTag(String localName) voidwriteEndTag(String prefix, String localName) voidwriteEntityReference(String name) protected final voidprotected final voidwriteNameUnchecked(String name) intprotected abstract intwritePIData(String data) final voidfinal voidwritePIStart(String target, boolean addSpace) abstract voidwriteRaw(char[] cbuf, int offset, int len) abstract voidfinal voidwriteRawAscii(char[] buf, int offset, int len) LikeXmlWriter.writeRaw(String, int, int), but caller guarantees that the contents additionally are known to be in 7-bit ascii range.voidvoidvoidwriteStartTagStart(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, 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.voidwriteTypedAttribute(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.voidwriteTypedAttribute(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 voidwriteTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) Non-validating version of typed write methodfinal voidwriteTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc, org.codehaus.stax2.validation.XMLValidator validator, char[] copyBuffer) Validating version of typed write methodvoidwriteXmlDeclaration(String version, String encoding, String standalone) Methods inherited from class 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 eitherwriteRaworwriteCharacters), 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:
getOutputPtrin classXmlWriter
-
getOutputStream
- Specified by:
getOutputStreamin classXmlWriter- Returns:
- Underlying OutputStream used for physical output, if the writer was constructed using one
-
getWriter
-
close
Description 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
- Specified by:
flushin classXmlWriter- Throws:
IOException
-
writeRaw
- Specified by:
writeRawin classXmlWriter- Throws:
IOException
-
writeRaw
- Specified by:
writeRawin classXmlWriter- Throws:
IOException
-
writeCDataStart
- Specified by:
writeCDataStartin classXmlWriter- Throws:
IOException
-
writeCDataEnd
- Specified by:
writeCDataEndin classXmlWriter- Throws:
IOException
-
writeCommentStart
- Specified by:
writeCommentStartin classXmlWriter- Throws:
IOException
-
writeCommentEnd
- Specified by:
writeCommentEndin classXmlWriter- Throws:
IOException
-
writePIStart
- Specified by:
writePIStartin classXmlWriter- Throws:
IOException
-
writePIEnd
- Specified by:
writePIEndin classXmlWriter- Throws:
IOException
-
writeCData
- 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
- Specified by:
writeCDatain classXmlWriter- Throws:
IOException
-
writeCharacters
- Specified by:
writeCharactersin classXmlWriter- Throws:
IOException
-
writeCharacters
- Specified by:
writeCharactersin 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:
writeCommentin classXmlWriter- Throws:
IOException
-
writeDTD
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
- 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
- Specified by:
writePIin classXmlWriter- Throws:
IOExceptionXMLStreamException
-
writeStartTagStart
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
- Specified by:
writeStartTagEndin classXmlWriter- Throws:
IOException
-
writeStartTagEmptyEnd
- Specified by:
writeStartTagEmptyEndin classXmlWriter- Throws:
IOException
-
writeEndTag
- Specified by:
writeEndTagin classXmlWriter- Throws:
IOException
-
writeEndTag
- Specified by:
writeEndTagin classXmlWriter- Throws:
IOException
-
writeAttribute
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(org.codehaus.stax2.ri.typed.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(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:
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, org.codehaus.stax2.ri.typed.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, org.codehaus.stax2.ri.typed.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, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc, org.codehaus.stax2.validation.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
- Throws:
IOException
-
writeAscii
- Throws:
IOException
-
writeAscii
- Throws:
IOException
-
writeAscii
- Throws:
IOException
-
writeRawAscii
Description copied from class:XmlWriterLikeXmlWriter.writeRaw(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
Entity writing can be optimized quite nicely, since it only needs to output ascii characters.- Returns:
- New value of
mOutputPtr - Throws:
IOException
-
writeName
- Throws:
IOExceptionXMLStreamException
-
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:
IOExceptionXMLStreamException
-
writeTextContent
- Throws:
IOException
-
writeTextContent
- Throws:
IOException
-