Package com.fasterxml.aalto.out
Class ByteXmlWriter
java.lang.Object
com.fasterxml.aalto.out.WNameFactory
com.fasterxml.aalto.out.XmlWriter
com.fasterxml.aalto.out.ByteXmlWriter
- Direct Known Subclasses:
SingleByteXmlWriter
,Utf8XmlWriter
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 Summary
FieldsModifier and TypeFieldDescriptionprotected final XmlCharTypes
Validation tables used for verifying validity (and need for quoting)protected OutputStream
Actual Writer to use for outputting buffered data as appropriate.protected byte[]
protected final int
protected int
protected int
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.(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 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
Default intermediate copy buffer size, to be used for efficient access to String content.(package private) static final int
And this value determines size of the intermediate copy buffer to use.(package private) static final int
Let's try avoid short writes, since some output streams have high per-call penalty (like network streams).Fields inherited from class com.fasterxml.aalto.out.XmlWriter
_cfgNsAware, _checkContent, _checkNames, _config, _copyBuffer, _copyBufferLen, _locPastChars, _locRowNr, _locRowStartOffset, _xml11, ATTR_MIN_ARRAYCOPY, DEFAULT_COPYBUFFER_LEN, MIN_ARRAYCOPY, SURR1_FIRST, SURR1_LAST, SURR2_FIRST, SURR2_LAST
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ByteXmlWriter
(WriterConfig cfg, OutputStream out, XmlCharTypes charTypes) -
Method Summary
Modifier and TypeMethodDescriptionvoid
_closeTarget
(boolean doClose) void
protected final int
calcSurrogate
(int surr1, int surr2, String context) final WName
constructName
(String localName) constructName
(String prefix, String localName) protected abstract WName
doConstructName
(String localName) protected abstract WName
doConstructName
(String prefix, String localName) protected final int
fastWriteAttrValue
(char[] vbuf, int offset, int len, byte[] bbuf, int ptr) Method called to copy given attribute value, when it's known that it will completely fit in the output buffer without further checksfinal void
flush()
protected final void
protected static final byte[]
protected static final void
protected static final void
protected final int
private final void
longWriteCharacters
(String text) protected abstract void
output2ByteChar
(int ch) protected abstract int
outputMultiByteChar
(int ch, char[] cbuf, int inputOffset, int inputLen) Method called to output a character beyond basic 1- or 2-byte encoding (code 0x0800 and above); possibly using character entities, if necessaryprotected abstract int
outputStrictMultiByteChar
(int ch, char[] cbuf, int inputOffset, int inputLen) Method called to output a character beyond basic 1- or 2-byte encoding (code 0x0800 and above), without being able to use character entitiesprotected abstract void
outputSurrogates
(int surr1, int surr2) Method called to output a composite character, result of combining 2 surrogate characters.protected final void
protected final void
throwUnpairedSurrogate
(int code) protected void
verifyNameComponent
(String part) Method used to verify that a name component (prefix, local name) is a legal as per xml 1.0 specification.protected final void
writeAsEntity
(int c) final void
writeAttribute
(WName name, char[] vbuf, int offset, int vlen) final void
writeAttribute
(WName name, 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)final void
writeAttribute
(WName name, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) private final void
writeAttrNameEqQ
(WName name) protected final void
writeAttrValue
(char[] vbuf, int offset, int len) int
writeCData
(char[] cbuf, int offset, int len) int
writeCData
(String data) protected int
writeCDataContents
(char[] cbuf, int offset, int len) protected final void
protected final void
final void
writeCharacters
(char[] cbuf, int offset, int len) final void
writeCharacters
(String text) int
writeComment
(String data) Method that will try to output the content as specified.protected int
writeCommentContents
(char[] cbuf, int offset, int len) Note: the only way to fix comment contents is to inject a space to split up consecutive '--' (or '-' that ends a comment).protected final void
protected final void
void
void
Older "legacy" output method for outputting DOCTYPE declaration.final void
writeEndTag
(WName name) void
writeEntityReference
(WName name) protected final void
writeLongAttribute
(WName name, String value, int vlen) protected final void
protected final void
protected final void
int
protected int
writePIData
(char[] cbuf, int offset, int len) protected final void
writeRaw
(byte b) protected final void
writeRaw
(byte[] buf) protected final void
writeRaw
(byte[] buf, int offset, int len) protected final void
writeRaw
(byte b1, byte b2) abstract void
writeRaw
(char[] cbuf, int offset, int len) This method is heavily encoding-dependant, so it needs to be deferred to sub-classesfinal void
void
writeSpace
(char[] cbuf, int offset, int len) final void
writeSpace
(String data) private final void
writeSplitCharacters
(char[] cbuf, int offset, int len) This method is called when it is possible that the output may cross the output buffer boundary.void
final void
final void
writeStartTagStart
(WName name) 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
writeTypedValue
(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) void
writeXmlDeclaration
(String version, String encoding, String standalone) Methods inherited from class com.fasterxml.aalto.out.XmlWriter
close, enableXml11, getAbsOffset, getColumn, getHighestEncodable, getRow, guessEncodingBitSize, reportFailedEscaping, reportInvalidChar, reportInvalidEmptyName, reportNwfContent, reportNwfContent, reportNwfName, reportNwfName, throwOutputError, throwOutputError
-
Field Details
-
DEFAULT_FULL_BUFFER_SIZE
static final int DEFAULT_FULL_BUFFER_SIZEAnd this value determines size of the intermediate copy buffer to use.- See Also:
-
DEFAULT_COPY_BUFFER_SIZE
static final int DEFAULT_COPY_BUFFER_SIZEDefault 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:
-
SMALL_WRITE
static final int SMALL_WRITELet's try avoid short writes, since some output streams have high per-call penalty (like network streams).- 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:
-
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
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 _surrogateIn 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
Validation tables used for verifying validity (and need for quoting)
-
-
Constructor Details
-
ByteXmlWriter
-
-
Method Details
-
getOutputPtr
protected final int getOutputPtr()- Specified by:
getOutputPtr
in classXmlWriter
-
constructName
- Specified by:
constructName
in classXmlWriter
- Throws:
XMLStreamException
-
constructName
- Specified by:
constructName
in classXmlWriter
- Throws:
XMLStreamException
-
doConstructName
- Throws:
XMLStreamException
-
doConstructName
- Throws:
XMLStreamException
-
verifyNameComponent
Method used to verify that a name component (prefix, local name) is a legal as per xml 1.0 specification.- Throws:
IllegalArgumentException
- If name component contains an invalid (non-name; or for the initial characters, non-name-first) character.XMLStreamException
-
outputSurrogates
protected abstract void outputSurrogates(int surr1, int surr2) throws IOException, XMLStreamException Method called to output a composite character, result of combining 2 surrogate characters.- Throws:
IOException
XMLStreamException
-
output2ByteChar
- Throws:
IOException
XMLStreamException
-
outputStrictMultiByteChar
protected abstract int outputStrictMultiByteChar(int ch, char[] cbuf, int inputOffset, int inputLen) throws IOException, 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:
IOException
XMLStreamException
-
outputMultiByteChar
protected abstract int outputMultiByteChar(int ch, char[] cbuf, int inputOffset, int inputLen) throws IOException, 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:
IOException
XMLStreamException
-
_releaseBuffers
public void _releaseBuffers()- Overrides:
_releaseBuffers
in classXmlWriter
-
_closeTarget
- Specified by:
_closeTarget
in classXmlWriter
- Throws:
IOException
-
flush
- Specified by:
flush
in classXmlWriter
- Throws:
IOException
-
writeRaw
- Specified by:
writeRaw
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeRaw
public abstract void writeRaw(char[] cbuf, int offset, int len) throws IOException, XMLStreamException This method is heavily encoding-dependant, so it needs to be deferred to sub-classes- Specified by:
writeRaw
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
-
writeStartTagEnd
- Specified by:
writeStartTagEnd
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeStartTagEmptyEnd
- Specified by:
writeStartTagEmptyEnd
in classXmlWriter
- Throws:
IOException
-
writeEndTag
- Specified by:
writeEndTag
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
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 final void writeAttribute(WName name, char[] vbuf, int offset, int vlen) throws IOException, XMLStreamException - Specified by:
writeAttribute
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
fastWriteAttrValue
protected final int fastWriteAttrValue(char[] vbuf, int offset, int len, byte[] bbuf, int ptr) throws IOException, 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:
IOException
XMLStreamException
-
writeAttrValue
protected final void writeAttrValue(char[] vbuf, int offset, int len) throws IOException, XMLStreamException - Throws:
IOException
XMLStreamException
-
writeLongAttribute
protected final void writeLongAttribute(WName name, String value, int vlen) throws IOException, XMLStreamException - Throws:
IOException
XMLStreamException
-
writeName
- Throws:
IOException
-
writeName
- Throws:
IOException
-
writeName
- Throws:
IOException
-
writeAttrNameEqQ
- Throws:
IOException
XMLStreamException
-
writeCData
- Specified by:
writeCData
in classXmlWriter
- 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:
IOException
XMLStreamException
-
writeCData
- Specified by:
writeCData
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeCDataContents
protected int writeCDataContents(char[] cbuf, int offset, int len) throws IOException, XMLStreamException - Throws:
IOException
XMLStreamException
-
writeCharacters
- Specified by:
writeCharacters
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
longWriteCharacters
- Throws:
IOException
XMLStreamException
-
writeCharacters
public final void writeCharacters(char[] cbuf, int offset, int len) throws IOException, XMLStreamException - Specified by:
writeCharacters
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeSplitCharacters
private final void writeSplitCharacters(char[] cbuf, int offset, int len) throws IOException, 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:
IOException
XMLStreamException
-
writeTypedValue
public void writeTypedValue(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws IOException, XMLStreamException - Specified by:
writeTypedValue
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeAttribute
public final void writeAttribute(WName name, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws IOException, XMLStreamException - Specified by:
writeAttribute
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
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
XMLStreamException
-
writeCommentContents
protected int writeCommentContents(char[] cbuf, int offset, int len) throws IOException, XMLStreamException Note: the only way to fix comment contents is to inject a space to split up consecutive '--' (or '-' that ends a comment).- Throws:
IOException
XMLStreamException
-
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
XMLStreamException
-
writeDTD
public void writeDTD(WName rootName, String systemId, String publicId, String internalSubset) throws IOException, XMLStreamException - Specified by:
writeDTD
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writePIData
- Throws:
IOException
XMLStreamException
-
writeEntityReference
- Specified by:
writeEntityReference
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writePI
- Specified by:
writePI
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeSpace
- Specified by:
writeSpace
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeSpace
- Specified by:
writeSpace
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeXmlDeclaration
public void writeXmlDeclaration(String version, String encoding, String standalone) throws IOException, XMLStreamException - Specified by:
writeXmlDeclaration
in classXmlWriter
- Throws:
IOException
XMLStreamException
-
writeCDataStart
- Throws:
IOException
-
writeCDataEnd
- Throws:
IOException
-
writeCommentStart
- Throws:
IOException
-
writeCommentEnd
- Throws:
IOException
-
writeRaw
- Throws:
IOException
-
writeRaw
- Throws:
IOException
-
writeRaw
- Throws:
IOException
-
writeRaw
- Throws:
IOException
-
throwUnpairedSurrogate
- Throws:
IOException
-
throwUnpairedSurrogate
- Throws:
IOException
-
flushBuffer
- Throws:
IOException
-
writeAsEntity
- Throws:
IOException
-
calcSurrogate
- Throws:
XMLStreamException
-
getAscii
-
getAscii
-
getAscii
-