public final class BufferingXmlWriter extends XmlWriter implements 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 |
|---|---|
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.
|
protected 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 OutputStream |
mUnderlyingStream
Actual physical stream that the writer is using, if known.
|
protected static int[] |
QUOTABLE_TEXT_CHARS |
DEFAULT_QUOTE_CHAR, mAttrValueWriter, mAutoCloseOutput, mCheckContent, mCheckNames, mCheckStructure, mConfig, mEncoding, mFixContent, mLocPastChars, mLocRowNr, mLocRowStartOffset, mNsAware, mRawWrapper, mTextWrapper, mTextWriter, mXml11, SURR1_FIRST, SURR1_LAST, SURR2_FIRST, SURR2_LASTATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT| Constructor and Description |
|---|
BufferingXmlWriter(Writer out,
WriterConfig cfg,
String enc,
boolean autoclose,
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.
|
void |
flush() |
protected int |
getOutputPtr() |
protected OutputStream |
getOutputStream() |
protected Writer |
getWriter() |
static int |
guessEncodingBitSize(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(String content) |
protected int |
verifyCommentContent(String content) |
protected void |
writeAsEntity(int c) |
void |
writeAttribute(String localName,
char[] value,
int offset,
int vlen) |
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 vlen) |
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)
|
int |
writeCData(char[] cbuf,
int offset,
int len) |
int |
writeCData(String data) |
void |
writeCDataEnd() |
void |
writeCDataStart() |
void |
writeCharacters(char[] cbuf,
int offset,
int len) |
void |
writeCharacters(String text) |
int |
writeComment(String data)
Method that will try to output the content as specified.
|
void |
writeCommentEnd() |
void |
writeCommentStart() |
void |
writeDTD(String data)
Older "legacy" output method for outputting DOCTYPE declaration.
|
void |
writeDTD(String rootName,
String systemId,
String publicId,
String internalSubset) |
void |
writeEndTag(String localName) |
void |
writeEndTag(String prefix,
String localName) |
void |
writeEntityReference(String name) |
int |
writePI(String target,
String data) |
void |
writePIEnd() |
void |
writePIStart(String target,
boolean addSpace) |
protected void |
writePrefixedName(String prefix,
String localName) |
void |
writeRaw(char[] cbuf,
int offset,
int len) |
void |
writeRaw(String str) |
void |
writeRaw(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(String content,
int index) |
protected void |
writeSegmentedComment(String content,
int index) |
void |
writeStartTagEmptyEnd() |
void |
writeStartTagEnd() |
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)
|
void |
writeTypedAttribute(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(String prefix,
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(String prefix,
String localName,
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(String version,
String encoding,
String standalone) |
enableXml11, getAbsOffset, getColumn, getRow, handleInvalidChar, reportNwfContent, reportNwfName, reportNwfName, throwOutputError, throwOutputError, verifyNameValidity, wrapAsRawWriter, wrapAsTextWriterprotected static final int HIGHEST_ENCODABLE_ATTR_CHAR
protected static final int HIGHEST_ENCODABLE_TEXT_CHAR
protected static final int[] QUOTABLE_TEXT_CHARS
protected final Writer mOut
protected char[] mOutputBuffer
protected final int mSmallWriteSize
protected int mOutputPtr
protected int mOutputBufLen
protected final OutputStream mUnderlyingStream
public BufferingXmlWriter(Writer out, WriterConfig cfg, String enc, boolean autoclose, OutputStream outs, int bitsize) throws IOException
outs - Underlying OutputStream that the writer
(out) is using, if known. Needed to support
(optional) access to the underlying streamIOExceptionprotected int getOutputPtr()
getOutputPtr in class XmlWriterprotected final OutputStream getOutputStream()
getOutputStream in class XmlWriterprotected final Writer getWriter()
public void close(boolean forceRealClose)
throws IOException
XmlWriterclose in class XmlWriterIOExceptionpublic final void flush()
throws IOException
flush in class XmlWriterIOExceptionpublic void writeRaw(char[] cbuf,
int offset,
int len)
throws IOException
writeRaw in class XmlWriterIOExceptionpublic final void writeRawAscii(char[] cbuf,
int offset,
int len)
throws IOException
writeRawAscii in class XmlWriterIOExceptionpublic void writeRaw(String str) throws IOException
writeRaw in class XmlWriterIOExceptionpublic void writeRaw(String str, int offset, int len) throws IOException
writeRaw in class XmlWriterIOExceptionpublic final void writeCDataStart()
throws IOException
writeCDataStart in class XmlWriterIOExceptionpublic final void writeCDataEnd()
throws IOException
writeCDataEnd in class XmlWriterIOExceptionpublic final void writeCommentStart()
throws IOException
writeCommentStart in class XmlWriterIOExceptionpublic final void writeCommentEnd()
throws IOException
writeCommentEnd in class XmlWriterIOExceptionpublic final void writePIStart(String target, boolean addSpace) throws IOException
writePIStart in class XmlWriterIOExceptionpublic final void writePIEnd()
throws IOException
writePIEnd in class XmlWriterIOExceptionpublic int writeCData(String data) throws IOException
writeCData in class XmlWriterdata - Contents of the CDATA section to write outIOExceptionpublic int writeCData(char[] cbuf,
int offset,
int len)
throws IOException
writeCData in class XmlWriterIOExceptionpublic void writeCharacters(String text) throws IOException
writeCharacters in class XmlWriterIOExceptionpublic void writeCharacters(char[] cbuf,
int offset,
int len)
throws IOException
writeCharacters in class XmlWriterIOExceptionpublic int writeComment(String data) throws IOException
writeComment in class XmlWriterIOExceptionpublic void writeDTD(String data) throws IOException
XmlWriterwriteDTD in class XmlWriterIOExceptionpublic void writeDTD(String rootName, String systemId, String publicId, String internalSubset) throws IOException, XMLStreamException
writeDTD in class XmlWriterIOExceptionXMLStreamExceptionpublic void writeEntityReference(String name) throws IOException, XMLStreamException
writeEntityReference in class XmlWriterIOExceptionXMLStreamExceptionpublic void writeXmlDeclaration(String version, String encoding, String standalone) throws IOException
writeXmlDeclaration in class XmlWriterIOExceptionpublic int writePI(String target, String data) throws IOException, XMLStreamException
writePI in class XmlWriterIOExceptionXMLStreamExceptionpublic void writeStartTagStart(String localName) throws IOException, 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 XmlWriterIOExceptionXMLStreamExceptionpublic void writeStartTagStart(String prefix, String localName) throws IOException, 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 XmlWriterIOExceptionXMLStreamExceptionpublic void writeStartTagEnd()
throws IOException
writeStartTagEnd in class XmlWriterIOExceptionpublic void writeStartTagEmptyEnd()
throws IOException
writeStartTagEmptyEnd in class XmlWriterIOExceptionpublic void writeEndTag(String localName) throws IOException
writeEndTag in class XmlWriterIOExceptionpublic void writeEndTag(String prefix, String localName) throws IOException
writeEndTag in class XmlWriterIOExceptionpublic void writeAttribute(String localName, String value) throws IOException, 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 XmlWriterIOExceptionXMLStreamExceptionpublic void writeAttribute(String localName, char[] value, int offset, int vlen) throws IOException, XMLStreamException
writeAttribute in class XmlWriterIOExceptionXMLStreamExceptionpublic void writeAttribute(String prefix, String localName, String value) throws IOException, 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 XmlWriterIOExceptionXMLStreamExceptionpublic void writeAttribute(String prefix, String localName, char[] value, int offset, int vlen) throws IOException, XMLStreamException
writeAttribute in class XmlWriterIOExceptionXMLStreamExceptionpublic final void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
throws 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 contentIOExceptionpublic final void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc,
org.codehaus.stax2.validation.XMLValidator validator,
char[] copyBuffer)
throws IOException,
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 necessaryIOExceptionXMLStreamExceptionpublic void writeTypedAttribute(String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws IOException, 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 XmlWriterIOExceptionXMLStreamExceptionpublic void writeTypedAttribute(String prefix, String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws IOException, 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 XmlWriterIOExceptionXMLStreamExceptionpublic 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
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 XmlWriterIOExceptionXMLStreamExceptionprotected final void writePrefixedName(String prefix, String localName) throws IOException
IOExceptionprotected int verifyCDataContent(String content)
protected int verifyCDataContent(char[] c,
int start,
int end)
protected int verifyCommentContent(String content)
protected void writeSegmentedCData(String content, int index) throws IOException
IOExceptionprotected void writeSegmentedCData(char[] c,
int start,
int len,
int index)
throws IOException
IOExceptionprotected void writeSegmentedComment(String content, int index) throws IOException
IOExceptionpublic static int guessEncodingBitSize(String enc)
protected final void writeAsEntity(int c)
throws IOException
IOExceptionCopyright © 2018 FasterXML. All rights reserved.