Top Description Fields Constructors Methods
com.fasterxml.aalto.out

public abstract Class ByteXmlWriter

extends XmlWriter
Class Inheritance
Known Direct Subclasses
com.fasterxml.aalto.out.SingleByteXmlWriter, com.fasterxml.aalto.out.Utf8XmlWriter
Imports
java.io.*, javax.xml.stream.*, org.codehaus.stax2.ri.typed.AsciiValueEncoder, com.fasterxml.aalto.impl.ErrorConsts, com.fasterxml.aalto.util.XmlCharTypes, .XmlChars, .XmlConsts

This abstract base class (partial implementation of XmlWriter) is used if the destination is byte-based java.io.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

Modifier and TypeField and Description
protected final XmlCharTypes
_charTypes

Validation tables used for verifying validity (and need for quoting)

protected OutputStream
_out

Actual Writer to use for outputting buffered data as appropriate.

protected byte[]
protected final int
protected int
protected int
_surrogate

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.

pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte
pack-priv static final byte[]
pack-priv static final byte[]
pack-priv static final byte[]
pack-priv static final byte[]
pack-priv static final byte[]
pack-priv static final byte[]
pack-priv static final byte[]
pack-priv static final int
DEFAULT_COPY_BUFFER_SIZE

Default intermediate copy buffer size, to be used for efficient access to String content.

pack-priv static final int
DEFAULT_FULL_BUFFER_SIZE

And this value determines size of the intermediate copy buffer to use.

pack-priv static final int
SMALL_WRITE

Let's try avoid short writes, since some output streams have high per-call penalty (like network streams).

Inherited from com.fasterxml.aalto.out.XmlWriter:
_cfgNsAware_checkContent_checkNames_config_copyBuffer_copyBufferLen_locPastChars_locRowNr_locRowStartOffset_xml11ATTR_MIN_ARRAYCOPYDEFAULT_COPYBUFFER_LENMIN_ARRAYCOPYSURR1_FIRSTSURR1_LASTSURR2_FIRSTSURR2_LAST

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
_closeTarget(boolean doClose)

Implements abstract com.fasterxml.aalto.out.XmlWriter._closeTarget.

public void
protected final int
calcSurrogate(int surr1, int surr2, String context)

public final WName
public WName
protected abstract WName
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 checks

public final void
protected final void
protected static final byte[]
protected static final void
getAscii(String str, byte[] result)

protected static final void
getAscii(String str, byte[] result, int offset)

protected final int
private final void
protected abstract void
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 necessary

protected 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 entities

protected 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
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
public final void
writeAttribute(WName name, String value)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeAttribute.

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)

public final void
writeAttribute(WName name, char[] vbuf, int offset, int vlen)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeAttribute.

public final void
private final void
protected final void
writeAttrValue(char[] vbuf, int offset, int len)

public int

Returns:

-1 to indicate succesful write, or index of the problematic character in input (first ']' from "]]>" sequence, in non-fixing mode)
writeCData
(String
Contents of the CDATA section to write out
data
)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeCData.

public int
writeCData(char[] cbuf, int offset, int len)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeCData.

protected int
writeCDataContents(char[] cbuf, int offset, int len)

protected final void
protected final void
public final void
public final void
writeCharacters(char[] cbuf, int offset, int len)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeCharacters.

public int
writeComment(String data)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeComment.

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 consequtive '--' (or '-' that ends a comment).

protected final void
protected final void
public void
writeDTD(String data)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeDTD.

Older "legacy" output method for outputting DOCTYPE declaration.
public void
writeDTD(WName rootName, String systemId, String publicId, String internalSubset)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeDTD.

public final void
public void
protected final void
writeLongAttribute(WName name, String value, int vlen)

protected final void
protected final void
writeName(byte preChar, WName name)

protected final void
writeName(WName name, byte postChar)

public int
protected int
writePIData(char[] cbuf, int offset, int len)

public final void
writeRaw(String text, int offset, int len)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeRaw.

public abstract void
writeRaw(char[] cbuf, int offset, int len)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeRaw.

This method is heavily encoding-dependant, so it needs to be deferred to sub-classes
protected final void
writeRaw(byte b)

protected final void
writeRaw(byte b1, byte b2)

protected final void
writeRaw(byte[] buf)

protected final void
writeRaw(byte[] buf, int offset, int len)

public final void
public void
writeSpace(char[] cbuf, int offset, int len)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeSpace.

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.

public void
public final void
public final void
writeStartTagStart(WName name)

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeStartTagStart.

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)

public void
public void
Inherited from com.fasterxml.aalto.out.XmlWriter:
closeenableXml11getAbsOffsetgetColumngetHighestEncodablegetRowguessEncodingBitSizereportFailedEscapingreportInvalidCharreportInvalidEmptyNamereportNwfContentreportNwfContentreportNwfNamereportNwfNamethrowOutputErrorthrowOutputError

Field Detail

_charTypesback to summary
protected final XmlCharTypes _charTypes

Validation tables used for verifying validity (and need for quoting)

_outback to summary
protected OutputStream _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.

_outputBufferback to summary
protected byte[] _outputBuffer
_outputBufferLenback to summary
protected final int _outputBufferLen
_outputPtrback to summary
protected int _outputPtr
_surrogateback to summary
protected int _surrogate

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.

BYTE_Aback to summary
pack-priv static final byte BYTE_A
BYTE_AMPback to summary
pack-priv static final byte BYTE_AMP
BYTE_APOSback to summary
pack-priv static final byte BYTE_APOS
BYTE_COLONback to summary
pack-priv static final byte BYTE_COLON
BYTE_EQback to summary
pack-priv static final byte BYTE_EQ
BYTE_Gback to summary
pack-priv static final byte BYTE_G
BYTE_GTback to summary
pack-priv static final byte BYTE_GT
BYTE_HASHback to summary
pack-priv static final byte BYTE_HASH
BYTE_HYPHENback to summary
pack-priv static final byte BYTE_HYPHEN
BYTE_Lback to summary
pack-priv static final byte BYTE_L
BYTE_LBRACKETback to summary
pack-priv static final byte BYTE_LBRACKET
BYTE_LTback to summary
pack-priv static final byte BYTE_LT
BYTE_Mback to summary
pack-priv static final byte BYTE_M
BYTE_Oback to summary
pack-priv static final byte BYTE_O
BYTE_Pback to summary
pack-priv static final byte BYTE_P
BYTE_Qback to summary
pack-priv static final byte BYTE_Q
BYTE_QMARKback to summary
pack-priv static final byte BYTE_QMARK
BYTE_QUOTback to summary
pack-priv static final byte BYTE_QUOT
BYTE_RBRACKETback to summary
pack-priv static final byte BYTE_RBRACKET
BYTE_Sback to summary
pack-priv static final byte BYTE_S
BYTE_SEMICOLONback to summary
pack-priv static final byte BYTE_SEMICOLON
BYTE_SLASHback to summary
pack-priv static final byte BYTE_SLASH
BYTE_SPACEback to summary
pack-priv static final byte BYTE_SPACE
BYTE_Tback to summary
pack-priv static final byte BYTE_T
BYTE_Uback to summary
pack-priv static final byte BYTE_U
BYTE_Xback to summary
pack-priv static final byte BYTE_X
BYTES_CDATA_ENDback to summary
pack-priv static final byte[] BYTES_CDATA_END
BYTES_CDATA_STARTback to summary
pack-priv static final byte[] BYTES_CDATA_START
BYTES_COMMENT_ENDback to summary
pack-priv static final byte[] BYTES_COMMENT_END
BYTES_COMMENT_STARTback to summary
pack-priv static final byte[] BYTES_COMMENT_START
BYTES_XMLDECL_ENCODINGback to summary
pack-priv static final byte[] BYTES_XMLDECL_ENCODING
BYTES_XMLDECL_STANDALONEback to summary
pack-priv static final byte[] BYTES_XMLDECL_STANDALONE
BYTES_XMLDECL_STARTback to summary
pack-priv static final byte[] BYTES_XMLDECL_START
DEFAULT_COPY_BUFFER_SIZEback to summary
pack-priv static final int DEFAULT_COPY_BUFFER_SIZE

Default 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

DEFAULT_FULL_BUFFER_SIZEback to summary
pack-priv static final int DEFAULT_FULL_BUFFER_SIZE

And this value determines size of the intermediate copy buffer to use.

SMALL_WRITEback to summary
pack-priv static final int SMALL_WRITE

Let's try avoid short writes, since some output streams have high per-call penalty (like network streams).

Constructor Detail

ByteXmlWriterback to summary
protected ByteXmlWriter(WriterConfig cfg, OutputStream out, XmlCharTypes charTypes)

Method Detail

_closeTargetback to summary
public void _closeTarget(boolean doClose) throws IOException

Implements abstract com.fasterxml.aalto.out.XmlWriter._closeTarget.

Annotations
@Override
_releaseBuffersback to summary
public void _releaseBuffers()

Overrides com.fasterxml.aalto.out.XmlWriter._releaseBuffers.

Annotations
@Override
calcSurrogateback to summary
protected final int calcSurrogate(int surr1, int surr2, String context) throws XMLStreamException
constructNameback to summary
public final WName constructName(String localName) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.constructName.

Annotations
@Override
constructNameback to summary
public WName constructName(String prefix, String localName) throws XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.constructName.

Annotations
@Override
doConstructNameback to summary
protected abstract WName doConstructName(String localName) throws XMLStreamException
doConstructNameback to summary
protected abstract WName doConstructName(String prefix, String localName) throws XMLStreamException
fastWriteAttrValueback to summary
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

flushback to summary
public final void flush() throws IOException

Implements abstract com.fasterxml.aalto.out.XmlWriter.flush.

Annotations
@Override
flushBufferback to summary
protected final void flushBuffer() throws IOException
getAsciiback to summary
protected static final byte[] getAscii(String str)
getAsciiback to summary
protected static final void getAscii(String str, byte[] result)
getAsciiback to summary
protected static final void getAscii(String str, byte[] result, int offset)
getOutputPtrback to summary
protected final int getOutputPtr()

Implements abstract com.fasterxml.aalto.out.XmlWriter.getOutputPtr.

Annotations
@Override
longWriteCharactersback to summary
private final void longWriteCharacters(String text) throws IOException, XMLStreamException
output2ByteCharback to summary
protected abstract void output2ByteChar(int ch) throws IOException, XMLStreamException
outputMultiByteCharback to summary
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

outputStrictMultiByteCharback to summary
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

outputSurrogatesback to summary
protected abstract void outputSurrogates(int surr1, int surr2) throws IOException, XMLStreamException

Method called to output a composite character, result of combining 2 surrogate characters.

throwUnpairedSurrogateback to summary
protected final void throwUnpairedSurrogate() throws IOException
throwUnpairedSurrogateback to summary
protected final void throwUnpairedSurrogate(int code) throws IOException
verifyNameComponentback to summary
protected void verifyNameComponent(String part) throws XMLStreamException

Method used to verify that a name component (prefix, local name) is a legal as per xml 1.0 specification.

Exceptions
IllegalArgumentException:
If name component contains an invalid (non-name; or for the initial characters, non-name-first) character.
writeAsEntityback to summary
protected final void writeAsEntity(int c) throws IOException
writeAttributeback to summary
public final void writeAttribute(WName name, String value) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeAttribute.

Doc from com.fasterxml.aalto.out.XmlWriter.writeAttribute.

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)

Annotations
@Override
writeAttributeback to summary
public final void writeAttribute(WName name, char[] vbuf, int offset, int vlen) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeAttribute.

Annotations
@Override
writeAttributeback to summary
public final void writeAttribute(WName name, AsciiValueEncoder enc) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeAttribute.

Annotations
@Override
writeAttrNameEqQback to summary
private final void writeAttrNameEqQ(WName name) throws IOException, XMLStreamException
writeAttrValueback to summary
protected final void writeAttrValue(char[] vbuf, int offset, int len) throws IOException, XMLStreamException
writeCDataback to summary
public int writeCData(String data) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeCData.

Parameters
data:String

Doc from com.fasterxml.aalto.out.XmlWriter.writeCData.

Contents of the CDATA section to write out

Returns:int

-1 to indicate succesful write, or index of the problematic character in input (first ']' from "]]>" sequence, in non-fixing mode)

Annotations
@Override
writeCDataback to summary
public int writeCData(char[] cbuf, int offset, int len) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeCData.

Annotations
@Override
writeCDataContentsback to summary
protected int writeCDataContents(char[] cbuf, int offset, int len) throws IOException, XMLStreamException
writeCDataEndback to summary
protected final void writeCDataEnd() throws IOException
writeCDataStartback to summary
protected final void writeCDataStart() throws IOException
writeCharactersback to summary
public final void writeCharacters(String text) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeCharacters.

Annotations
@Override
writeCharactersback to summary
public final void writeCharacters(char[] cbuf, int offset, int len) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeCharacters.

Annotations
@Override
writeCommentback to summary
public int writeComment(String data) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.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.

Annotations
@Override
writeCommentContentsback to summary
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 consequtive '--' (or '-' that ends a comment).

writeCommentEndback to summary
protected final void writeCommentEnd() throws IOException
writeCommentStartback to summary
protected final void writeCommentStart() throws IOException
writeDTDback to summary
public void writeDTD(String data) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeDTD.

Doc from com.fasterxml.aalto.out.XmlWriter.writeDTD.

Older "legacy" output method for outputting DOCTYPE declaration. Assumes that the passed-in String contains a complete DOCTYPE declaration properly quoted.

Annotations
@Override
writeDTDback to summary
public void writeDTD(WName rootName, String systemId, String publicId, String internalSubset) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeDTD.

Annotations
@Override
writeEndTagback to summary
public final void writeEndTag(WName name) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeEndTag.

Annotations
@Override
writeEntityReferenceback to summary
public void writeEntityReference(WName name) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeEntityReference.

Annotations
@Override
writeLongAttributeback to summary
protected final void writeLongAttribute(WName name, String value, int vlen) throws IOException, XMLStreamException
writeNameback to summary
protected final void writeName(WName name) throws IOException
writeNameback to summary
protected final void writeName(byte preChar, WName name) throws IOException
writeNameback to summary
protected final void writeName(WName name, byte postChar) throws IOException
writePIback to summary
public int writePI(WName target, String data) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writePI.

Annotations
@Override
writePIDataback to summary
protected int writePIData(char[] cbuf, int offset, int len) throws IOException, XMLStreamException
writeRawback to summary
public final void writeRaw(String text, int offset, int len) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeRaw.

Annotations
@Override
writeRawback to summary
public abstract void writeRaw(char[] cbuf, int offset, int len) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeRaw.

This method is heavily encoding-dependant, so it needs to be deferred to sub-classes

Annotations
@Override
writeRawback to summary
protected final void writeRaw(byte b) throws IOException
writeRawback to summary
protected final void writeRaw(byte b1, byte b2) throws IOException
writeRawback to summary
protected final void writeRaw(byte[] buf) throws IOException
writeRawback to summary
protected final void writeRaw(byte[] buf, int offset, int len) throws IOException
writeSpaceback to summary
public final void writeSpace(String data) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeSpace.

Annotations
@Override
writeSpaceback to summary
public void writeSpace(char[] cbuf, int offset, int len) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeSpace.

Annotations
@Override
writeSplitCharactersback to summary
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.

writeStartTagEmptyEndback to summary
public void writeStartTagEmptyEnd() throws IOException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeStartTagEmptyEnd.

Annotations
@Override
writeStartTagEndback to summary
public final void writeStartTagEnd() throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeStartTagEnd.

Annotations
@Override
writeStartTagStartback to summary
public final void writeStartTagStart(WName name) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeStartTagStart.

Doc from com.fasterxml.aalto.out.XmlWriter.writeStartTagStart.

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)

Annotations
@Override
writeTypedValueback to summary
public void writeTypedValue(AsciiValueEncoder enc) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeTypedValue.

Annotations
@Override
writeXmlDeclarationback to summary
public void writeXmlDeclaration(String version, String encoding, String standalone) throws IOException, XMLStreamException

Implements abstract com.fasterxml.aalto.out.XmlWriter.writeXmlDeclaration.

Annotations
@Override