public final class BufferingXmlWriter extends XmlWriter implements javax.xml.stream.XMLStreamConstants
XmlWriter that will dispatch writes
to another writer (of type Writer, and will NOT handle
encoding. It will, however, do basic buffering such that the underlying
Writer need (and thus, should) not do buffering.
One design goal for this class is to avoid unnecessary buffering: since there will be another Writer doing the actual encoding, amount of buffering needed should still be limited. To this end, a threshold is used to define what's the threshold of writes that we do want to coalesce, ie. buffer. Writes bigger than this should in general proceed without buffering.
| Modifier and Type | Field and Description |
|---|---|
(package private) static int |
DEFAULT_BUFFER_SIZE
Let's use a typical default to have a compromise between large
enough chunks to output, and minimizing memory overhead.
|
(package private) static int |
DEFAULT_SMALL_SIZE
Choosing threshold for 'small size' is a compromise between
excessive buffering (high small size), and too many fragmented
calls to the underlying writer (low small size).
|
protected static int |
HIGHEST_ENCODABLE_ATTR_CHAR
Highest valued character that may need to be encoded (minus charset
encoding requirements) when writing attribute values.
|
protected static int |
HIGHEST_ENCODABLE_TEXT_CHAR
Highest valued character that may need to be encoded (minus charset
encoding requirements) when writing attribute values.
|
private int |
mEncHighChar
First Unicode character (one with lowest value) after (and including)
which character entities have to be used.
|
(package private) char |
mEncQuoteChar
Character that is considered to be the enclosing quote character;
for XML either single or double quote.
|
(package private) java.lang.String |
mEncQuoteEntity
Entity String to use for escaping the quote character.
|
protected java.io.Writer |
mOut
Actual Writer to use for outputting buffered data as appropriate.
|
protected char[] |
mOutputBuffer |
protected int |
mOutputBufLen |
protected int |
mOutputPtr |
protected int |
mSmallWriteSize
This is the threshold used to check what is considered a "small"
write; small writes will be buffered until resulting size will
be above the threshold.
|
protected java.io.OutputStream |
mUnderlyingStream
Actual physical stream that the writer is using, if known.
|
protected static int[] |
QUOTABLE_TEXT_CHARS |
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 and Description |
|---|
BufferingXmlWriter(java.io.Writer out,
WriterConfig cfg,
java.lang.String enc,
boolean autoclose,
java.io.OutputStream outs,
int bitsize) |
| Modifier and Type | Method and Description |
|---|---|
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.
|
private void |
fastWriteRaw(char c) |
private void |
fastWriteRaw(char c1,
char c2) |
private void |
fastWriteRaw(java.lang.String str) |
void |
flush() |
private void |
flushBuffer() |
protected int |
getOutputPtr() |
protected java.io.OutputStream |
getOutputStream() |
protected java.io.Writer |
getWriter() |
static int |
guessEncodingBitSize(java.lang.String enc)
Method used to figure out which part of the Unicode char set the
encoding can natively support.
|
protected int |
verifyCDataContent(char[] c,
int start,
int end) |
protected int |
verifyCDataContent(java.lang.String content) |
protected int |
verifyCommentContent(java.lang.String content) |
protected void |
writeAsEntity(int c) |
void |
writeAttribute(java.lang.String localName,
char[] value,
int offset,
int vlen) |
void |
writeAttribute(java.lang.String localName,
java.lang.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(java.lang.String prefix,
java.lang.String localName,
char[] value,
int offset,
int vlen) |
void |
writeAttribute(java.lang.String prefix,
java.lang.String localName,
java.lang.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)
|
private void |
writeAttrValue(char[] value,
int offset,
int len) |
private void |
writeAttrValue(java.lang.String value,
int len) |
int |
writeCData(char[] cbuf,
int offset,
int len) |
int |
writeCData(java.lang.String data) |
void |
writeCDataEnd() |
void |
writeCDataStart() |
void |
writeCharacters(char[] cbuf,
int offset,
int len) |
void |
writeCharacters(java.lang.String text) |
int |
writeComment(java.lang.String data)
Method that will try to output the content as specified.
|
void |
writeCommentEnd() |
void |
writeCommentStart() |
void |
writeDTD(java.lang.String data)
Older "legacy" output method for outputting DOCTYPE declaration.
|
void |
writeDTD(java.lang.String rootName,
java.lang.String systemId,
java.lang.String publicId,
java.lang.String internalSubset) |
void |
writeEndTag(java.lang.String localName) |
void |
writeEndTag(java.lang.String prefix,
java.lang.String localName) |
void |
writeEntityReference(java.lang.String name) |
int |
writePI(java.lang.String target,
java.lang.String data) |
void |
writePIEnd() |
void |
writePIStart(java.lang.String target,
boolean addSpace) |
protected void |
writePrefixedName(java.lang.String prefix,
java.lang.String localName) |
void |
writeRaw(char[] cbuf,
int offset,
int len) |
void |
writeRaw(java.lang.String str) |
void |
writeRaw(java.lang.String str,
int offset,
int len) |
void |
writeRawAscii(char[] cbuf,
int offset,
int len)
Method called to output typed values (int, long, double, float etc)
that are known not to contain any escapable characters, or anything
else beyond 7-bit ascii range.
|
protected void |
writeSegmentedCData(char[] c,
int start,
int len,
int index) |
protected void |
writeSegmentedCData(java.lang.String content,
int index) |
protected void |
writeSegmentedComment(java.lang.String content,
int index) |
void |
writeStartTagEmptyEnd() |
void |
writeStartTagEnd() |
void |
writeStartTagStart(java.lang.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(java.lang.String prefix,
java.lang.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 |
writeTypedAttribute(java.lang.String localName,
org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
Method similar to
XmlWriter.writeAttribute(String,String,char[],int,int)
but where is known not to require escaping. |
void |
writeTypedAttribute(java.lang.String prefix,
java.lang.String localName,
org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
Method similar to
XmlWriter.writeAttribute(String,String,char[],int,int)
but where is known not to require escaping. |
void |
writeTypedAttribute(java.lang.String prefix,
java.lang.String localName,
java.lang.String nsURI,
org.codehaus.stax2.ri.typed.AsciiValueEncoder enc,
org.codehaus.stax2.validation.XMLValidator validator,
char[] copyBuffer)
Method similar to
XmlWriter.writeAttribute(String,String,char[],int,int)
but where is known not to require escaping. |
void |
writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
Like
XmlWriter.writeRaw(java.lang.String, int, int), but caller guarantees that the contents
additionally are known to be in 7-bit ascii range, and also
passes an encoder object that will encode values only when
being handed a buffer to append to. |
void |
writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc,
org.codehaus.stax2.validation.XMLValidator validator,
char[] copyBuffer)
Like
XmlWriter.writeRaw(java.lang.String, int, int), but caller guarantees that the contents
additionally are known to be in 7-bit ascii range, and also
passes an encoder object that will encode values only when
being handed a buffer to append to. |
void |
writeXmlDeclaration(java.lang.String version,
java.lang.String encoding,
java.lang.String standalone) |
enableXml11, getAbsOffset, getColumn, getRow, handleInvalidChar, reportNwfContent, reportNwfName, reportNwfName, throwOutputError, throwOutputError, verifyNameValidity, wrapAsRawWriter, wrapAsTextWriterstatic final int DEFAULT_BUFFER_SIZE
static final int DEFAULT_SMALL_SIZE
protected static final int HIGHEST_ENCODABLE_ATTR_CHAR
protected static final int HIGHEST_ENCODABLE_TEXT_CHAR
protected static final int[] QUOTABLE_TEXT_CHARS
protected final java.io.Writer mOut
protected char[] mOutputBuffer
protected final int mSmallWriteSize
protected int mOutputPtr
protected int mOutputBufLen
protected final java.io.OutputStream mUnderlyingStream
private final int mEncHighChar
final char mEncQuoteChar
final java.lang.String mEncQuoteEntity
public BufferingXmlWriter(java.io.Writer out,
WriterConfig cfg,
java.lang.String enc,
boolean autoclose,
java.io.OutputStream outs,
int bitsize)
throws java.io.IOException
outs - Underlying OutputStream that the writer
(out) is using, if known. Needed to support
(optional) access to the underlying streamjava.io.IOExceptionprotected int getOutputPtr()
getOutputPtr in class XmlWriterprotected final java.io.OutputStream getOutputStream()
getOutputStream in class XmlWriterprotected final java.io.Writer getWriter()
public void close(boolean forceRealClose)
throws java.io.IOException
XmlWriterpublic final void flush()
throws java.io.IOException
public void writeRaw(char[] cbuf,
int offset,
int len)
throws java.io.IOException
public final void writeRawAscii(char[] cbuf,
int offset,
int len)
throws java.io.IOException
writeRawAscii in class XmlWriterjava.io.IOExceptionpublic void writeRaw(java.lang.String str)
throws java.io.IOException
public void writeRaw(java.lang.String str,
int offset,
int len)
throws java.io.IOException
public final void writeCDataStart()
throws java.io.IOException
writeCDataStart in class XmlWriterjava.io.IOExceptionpublic final void writeCDataEnd()
throws java.io.IOException
writeCDataEnd in class XmlWriterjava.io.IOExceptionpublic final void writeCommentStart()
throws java.io.IOException
writeCommentStart in class XmlWriterjava.io.IOExceptionpublic final void writeCommentEnd()
throws java.io.IOException
writeCommentEnd in class XmlWriterjava.io.IOExceptionpublic final void writePIStart(java.lang.String target,
boolean addSpace)
throws java.io.IOException
writePIStart in class XmlWriterjava.io.IOExceptionpublic final void writePIEnd()
throws java.io.IOException
writePIEnd in class XmlWriterjava.io.IOExceptionpublic int writeCData(java.lang.String data)
throws java.io.IOException
writeCData in class XmlWriterdata - Contents of the CDATA section to write outjava.io.IOExceptionpublic int writeCData(char[] cbuf,
int offset,
int len)
throws java.io.IOException
writeCData in class XmlWriterjava.io.IOExceptionpublic void writeCharacters(java.lang.String text)
throws java.io.IOException
writeCharacters in class XmlWriterjava.io.IOExceptionpublic void writeCharacters(char[] cbuf,
int offset,
int len)
throws java.io.IOException
writeCharacters in class XmlWriterjava.io.IOExceptionpublic int writeComment(java.lang.String data)
throws java.io.IOException
writeComment in class XmlWriterjava.io.IOExceptionpublic void writeDTD(java.lang.String data)
throws java.io.IOException
XmlWriterpublic void writeDTD(java.lang.String rootName,
java.lang.String systemId,
java.lang.String publicId,
java.lang.String internalSubset)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
public void writeEntityReference(java.lang.String name)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
writeEntityReference in class XmlWriterjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionpublic void writeXmlDeclaration(java.lang.String version,
java.lang.String encoding,
java.lang.String standalone)
throws java.io.IOException
writeXmlDeclaration in class XmlWriterjava.io.IOExceptionpublic int writePI(java.lang.String target,
java.lang.String data)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
public void writeStartTagStart(java.lang.String localName)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
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)
writeStartTagStart in class XmlWriterjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionpublic void writeStartTagStart(java.lang.String prefix,
java.lang.String localName)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
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)
writeStartTagStart in class XmlWriterjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionpublic void writeStartTagEnd()
throws java.io.IOException
writeStartTagEnd in class XmlWriterjava.io.IOExceptionpublic void writeStartTagEmptyEnd()
throws java.io.IOException
writeStartTagEmptyEnd in class XmlWriterjava.io.IOExceptionpublic void writeEndTag(java.lang.String localName)
throws java.io.IOException
writeEndTag in class XmlWriterjava.io.IOExceptionpublic void writeEndTag(java.lang.String prefix,
java.lang.String localName)
throws java.io.IOException
writeEndTag in class XmlWriterjava.io.IOExceptionpublic void writeAttribute(java.lang.String localName,
java.lang.String value)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
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)
writeAttribute in class XmlWriterjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionpublic void writeAttribute(java.lang.String localName,
char[] value,
int offset,
int vlen)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
writeAttribute in class XmlWriterjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionpublic void writeAttribute(java.lang.String prefix,
java.lang.String localName,
java.lang.String value)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
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)
writeAttribute in class XmlWriterjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionpublic void writeAttribute(java.lang.String prefix,
java.lang.String localName,
char[] value,
int offset,
int vlen)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
writeAttribute in class XmlWriterjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionprivate final void writeAttrValue(java.lang.String value,
int len)
throws java.io.IOException
java.io.IOExceptionprivate final void writeAttrValue(char[] value,
int offset,
int len)
throws java.io.IOException
java.io.IOExceptionpublic final void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
throws java.io.IOException
XmlWriterXmlWriter.writeRaw(java.lang.String, int, int), but caller guarantees that the contents
additionally are known to be in 7-bit ascii range, and also
passes an encoder object that will encode values only when
being handed a buffer to append to.writeTypedElement in class XmlWriterenc - Encoder that will produce contentjava.io.IOExceptionpublic final void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc,
org.codehaus.stax2.validation.XMLValidator validator,
char[] copyBuffer)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
XmlWriterXmlWriter.writeRaw(java.lang.String, int, int), but caller guarantees that the contents
additionally are known to be in 7-bit ascii range, and also
passes an encoder object that will encode values only when
being handed a buffer to append to.writeTypedElement in class XmlWriterenc - 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 necessaryjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionpublic void writeTypedAttribute(java.lang.String localName,
org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
XmlWriterXmlWriter.writeAttribute(String,String,char[],int,int)
but where is known not to require escaping.
No validation needs to be performed.writeTypedAttribute in class XmlWriterjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionpublic void writeTypedAttribute(java.lang.String prefix,
java.lang.String localName,
org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
XmlWriterXmlWriter.writeAttribute(String,String,char[],int,int)
but where is known not to require escaping.
No validation needs to be performed.writeTypedAttribute in class XmlWriterjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionpublic void writeTypedAttribute(java.lang.String prefix,
java.lang.String localName,
java.lang.String nsURI,
org.codehaus.stax2.ri.typed.AsciiValueEncoder enc,
org.codehaus.stax2.validation.XMLValidator validator,
char[] copyBuffer)
throws java.io.IOException,
javax.xml.stream.XMLStreamException
XmlWriterXmlWriter.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.writeTypedAttribute in class XmlWriterjava.io.IOExceptionjavax.xml.stream.XMLStreamExceptionprotected final void writePrefixedName(java.lang.String prefix,
java.lang.String localName)
throws java.io.IOException
java.io.IOExceptionprivate final void flushBuffer()
throws java.io.IOException
java.io.IOExceptionprivate final void fastWriteRaw(char c)
throws java.io.IOException
java.io.IOExceptionprivate final void fastWriteRaw(char c1,
char c2)
throws java.io.IOException
java.io.IOExceptionprivate final void fastWriteRaw(java.lang.String str)
throws java.io.IOException
java.io.IOExceptionprotected int verifyCDataContent(java.lang.String content)
protected int verifyCDataContent(char[] c,
int start,
int end)
protected int verifyCommentContent(java.lang.String content)
protected void writeSegmentedCData(java.lang.String content,
int index)
throws java.io.IOException
java.io.IOExceptionprotected void writeSegmentedCData(char[] c,
int start,
int len,
int index)
throws java.io.IOException
java.io.IOExceptionprotected void writeSegmentedComment(java.lang.String content,
int index)
throws java.io.IOException
java.io.IOExceptionpublic static int guessEncodingBitSize(java.lang.String enc)
protected final void writeAsEntity(int c)
throws java.io.IOException
java.io.IOException