XmlWriter that will dispatch writes
to another writer (of type java.io.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 |
|---|---|
| pack-priv static final int | DEFAULT_BUFFER_SIZE
Let's use a typical default to have a compromise between large enough chunks to output, and minimizing memory overhead. |
| pack-priv static final 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 final int | HIGHEST_ENCODABLE_ATTR_CHAR
Highest valued character that may need to be encoded (minus charset encoding requirements) when writing attribute values. |
| protected static final int | HIGHEST_ENCODABLE_TEXT_CHAR
Highest valued character that may need to be encoded (minus charset encoding requirements) when writing attribute values. |
| private final int | mEncHighChar
First Unicode character (one with lowest value) after (and including) which character entities have to be used. |
| pack-priv final char | mEncQuoteChar
Character that is considered to be the enclosing quote character; for XML either single or double quote. |
| pack-priv final String | mEncQuoteEntity
Entity String to use for escaping the quote character. |
| protected final Writer | mOut
Actual Writer to use for outputting buffered data as appropriate. |
| protected char[] | |
| protected int | |
| protected int | |
| protected final 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 final OutputStream | mUnderlyingStream
Actual physical stream that the writer is using, if known. |
| protected static final int[] |
| Access | Constructor and Description |
|---|---|
| public | BufferingXmlWriter(Writer out, WriterConfig cfg, String enc, boolean autoclose, OutputStream
Underlying OutputStream that the writer
( outs, int bitsize)out) is using, if known. Needed to support
(optional) access to the underlying stream
|
| Modifier and Type | Method and Description |
|---|---|
| public void | close(boolean forceRealClose)
Implements abstract com. Method called to flush the buffer(s), and close the output sink (stream or writer) if enabled (auto-closing) or forced. |
| private final void | |
| private final void | |
| private final void | |
| public final void | |
| private final void | |
| protected int | |
| protected final OutputStream | |
| protected final Writer | |
| public static int | guessEncodingBitSize(String enc)
Method used to figure out which part of the Unicode char set the encoding can natively support. |
| protected int | Returns: Index at which a problem was found, if any; -1 if there's no problem.
|
| protected int | |
| protected int | |
| protected final void | |
| public void | writeAttribute(String localName, String value)
Implements abstract com. 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 | writeAttribute(String localName, char[] value, int offset, int vlen)
Implements abstract com.
|
| public void | writeAttribute(String prefix, String localName, String value)
Implements abstract com. 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 | writeAttribute(String prefix, String localName, char[] value, int offset, int vlen)
Implements abstract com.
|
| private final void | |
| private final void | |
| public int | writeCData(String
Contents of the CDATA section to write out data)Implements abstract com.
|
| public int | writeCData(char[] cbuf, int offset, int len)
Implements abstract com.
|
| public final void | |
| public final void | |
| public void | |
| public void | writeCharacters(char[] cbuf, int offset, int len)
Implements abstract com.
|
| public int | writeComment(String data)
Implements abstract com. Method that will try to output the content as specified. |
| public final void | |
| public final void | |
| public void | writeDTD(String data)
Implements abstract com. Older "legacy" output method for outputting DOCTYPE declaration. |
| public void | |
| public void | |
| public void | writeEndTag(String prefix, String localName)
Implements abstract com.
|
| public void | writeEntityReference(String name)
Implements abstract com.
|
| public int | |
| public final void | |
| public final void | writePIStart(String target, boolean addSpace)
Implements abstract com.
|
| protected final void | |
| public void | |
| public void | |
| public void | |
| public final void | writeRawAscii(char[] cbuf, int offset, int len)
Implements abstract com. 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 | |
| protected void | |
| protected void | |
| public void | |
| public void | |
| public void | writeStartTagStart(String localName)
Implements abstract com. 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 | writeStartTagStart(String prefix, String localName)
Implements abstract com. 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 | writeTypedAttribute(String localName, AsciiValueEncoder enc)
Implements abstract com. Method similar to |
| public void | writeTypedAttribute(String prefix, String localName, AsciiValueEncoder enc)
Implements abstract com. Method similar to |
| public void | writeTypedAttribute(String prefix, String localName, String nsURI, AsciiValueEncoder enc, XMLValidator validator, char[] copyBuffer)
Implements abstract com. Method similar to |
| public final void | writeTypedElement(AsciiValueEncoder
Encoder that will produce content enc)Implements abstract com. Like |
| public final void | writeTypedElement(AsciiValueEncoder
Encoder that will produce content enc, XMLValidator Validator to use for validating serialized textual
content (can not be null) validator, char[] Temporary buffer that writer can use for temporary
copies as necessary copyBuffer)Implements abstract com. Like |
| public void | writeXmlDeclaration(String version, String encoding, String standalone)
Implements abstract com.
|
| DEFAULT_BUFFER_SIZE | back to summary |
|---|---|
| pack-priv static final int DEFAULT_BUFFER_SIZE Let's use a typical default to have a compromise between large enough chunks to output, and minimizing memory overhead. Compared to encoding writers, buffer size can be bit smaller since there's one more level of processing (at encoding), which may use bigger buffering. | |
| DEFAULT_SMALL_SIZE | back to summary |
|---|---|
| pack-priv static final 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). Let's just use about 1/4 of the full buffer size. | |
| HIGHEST_ENCODABLE_ATTR_CHAR | back to summary |
|---|---|
| protected static final int HIGHEST_ENCODABLE_ATTR_CHAR Highest valued character that may need to be encoded (minus charset encoding requirements) when writing attribute values. | |
| HIGHEST_ENCODABLE_TEXT_CHAR | back to summary |
|---|---|
| protected static final int HIGHEST_ENCODABLE_TEXT_CHAR Highest valued character that may need to be encoded (minus charset encoding requirements) when writing attribute values. | |
| mEncHighChar | back to summary |
|---|---|
| private final int mEncHighChar First Unicode character (one with lowest value) after (and including) which character entities have to be used. For | |
| mEncQuoteChar | back to summary |
|---|---|
| pack-priv final char mEncQuoteChar Character that is considered to be the enclosing quote character; for XML either single or double quote. | |
| mEncQuoteEntity | back to summary |
|---|---|
| pack-priv final String mEncQuoteEntity Entity String to use for escaping the quote character. | |
| mOut | back to summary |
|---|---|
| protected final Writer mOut Actual Writer to use for outputting buffered data as appropriate. | |
| mOutputBuffer | back to summary |
|---|---|
| protected char[] mOutputBuffer | |
| mOutputBufLen | back to summary |
|---|---|
| protected int mOutputBufLen | |
| mOutputPtr | back to summary |
|---|---|
| protected int mOutputPtr | |
| mSmallWriteSize | back to summary |
|---|---|
| protected final 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. | |
| mUnderlyingStream | back to summary |
|---|---|
| protected final OutputStream mUnderlyingStream Actual physical stream that the writer is using, if known. Not used for actual output, only needed so that calling application may (try to) figure out the original source. | |
| QUOTABLE_TEXT_CHARS | back to summary |
|---|---|
| protected static final int[] QUOTABLE_TEXT_CHARS | |
| BufferingXmlWriter | back to summary |
|---|---|
public BufferingXmlWriter(Writer out, WriterConfig cfg, String enc, boolean autoclose, OutputStream outs, int bitsize) throws IOException
| |
| close | back to summary |
|---|---|
| public void close(boolean forceRealClose) throws IOException Implements abstract com. Doc from com. Method called to flush the buffer(s), and close the output sink (stream or writer) if enabled (auto-closing) or forced.
| |
| fastWriteRaw | back to summary |
|---|---|
| private final void fastWriteRaw(char c) throws IOException | |
| fastWriteRaw | back to summary |
|---|---|
| private final void fastWriteRaw(char c1, char c2) throws IOException | |
| fastWriteRaw | back to summary |
|---|---|
| private final void fastWriteRaw(String str) throws IOException | |
| flush | back to summary |
|---|---|
| public final void flush() throws IOException Implements abstract com.
| |
| flushBuffer | back to summary |
|---|---|
| private final void flushBuffer() throws IOException | |
| getOutputPtr | back to summary |
|---|---|
| protected int getOutputPtr() Implements abstract com.
| |
| getOutputStream | back to summary |
|---|---|
| protected final OutputStream getOutputStream() Implements abstract com.
| |
| getWriter | back to summary |
|---|---|
| protected final Writer getWriter() Implements abstract com.
| |
| guessEncodingBitSize | back to summary |
|---|---|
| public static int guessEncodingBitSize(String enc) Method used to figure out which part of the Unicode char set the encoding can natively support. Values returned are 7, 8 and 16, to indicate (respectively) "ascii", "ISO-Latin" and "native Unicode". These just best guesses, but should work ok for the most common encodings. | |
| verifyCDataContent | back to summary |
|---|---|
protected int verifyCDataContent(String content)
| |
| verifyCDataContent | back to summary |
|---|---|
| protected int verifyCDataContent(char[] c, int start, int end) | |
| verifyCommentContent | back to summary |
|---|---|
| protected int verifyCommentContent(String content) | |
| writeAsEntity | back to summary |
|---|---|
| protected final void writeAsEntity(int c) throws IOException | |
| writeAttribute | back to summary |
|---|---|
| public void writeAttribute(String localName, String value) throws IOException, XMLStreamException Implements abstract com. Doc from com. 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)
| |
| writeAttribute | back to summary |
|---|---|
| public void writeAttribute(String localName, char[] value, int offset, int vlen) throws IOException, XMLStreamException Implements abstract com.
| |
| writeAttribute | back to summary |
|---|---|
| public void writeAttribute(String prefix, String localName, String value) throws IOException, XMLStreamException Implements abstract com. Doc from com. 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)
| |
| writeAttribute | back to summary |
|---|---|
| public void writeAttribute(String prefix, String localName, char[] value, int offset, int vlen) throws IOException, XMLStreamException Implements abstract com.
| |
| writeAttrValue | back to summary |
|---|---|
| private final void writeAttrValue(String value, int len) throws IOException | |
| writeAttrValue | back to summary |
|---|---|
| private final void writeAttrValue(char[] value, int offset, int len) throws IOException | |
| writeCData | back to summary |
|---|---|
| public int writeCData(String data) throws IOException Implements abstract com.
| |
| writeCData | back to summary |
|---|---|
| public int writeCData(char[] cbuf, int offset, int len) throws IOException Implements abstract com.
| |
| writeCDataEnd | back to summary |
|---|---|
| public final void writeCDataEnd() throws IOException Implements abstract com.
| |
| writeCDataStart | back to summary |
|---|---|
| public final void writeCDataStart() throws IOException Implements abstract com.
| |
| writeCharacters | back to summary |
|---|---|
| public void writeCharacters(String text) throws IOException Implements abstract com.
| |
| writeCharacters | back to summary |
|---|---|
| public void writeCharacters(char[] cbuf, int offset, int len) throws IOException Implements abstract com.
| |
| writeComment | back to summary |
|---|---|
| public int writeComment(String data) throws IOException Implements abstract com. 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.
| |
| writeCommentEnd | back to summary |
|---|---|
| public final void writeCommentEnd() throws IOException Implements abstract com.
| |
| writeCommentStart | back to summary |
|---|---|
| public final void writeCommentStart() throws IOException Implements abstract com.
| |
| writeDTD | back to summary |
|---|---|
| public void writeDTD(String data) throws IOException Implements abstract com. Doc from com. Older "legacy" output method for outputting DOCTYPE declaration. Assumes that the passed-in String contains a complete DOCTYPE declaration properly quoted.
| |
| writeDTD | back to summary |
|---|---|
| public void writeDTD(String rootName, String systemId, String publicId, String internalSubset) throws IOException, XMLStreamException Implements abstract com.
| |
| writeEndTag | back to summary |
|---|---|
| public void writeEndTag(String localName) throws IOException Implements abstract com.
| |
| writeEndTag | back to summary |
|---|---|
| public void writeEndTag(String prefix, String localName) throws IOException Implements abstract com.
| |
| writeEntityReference | back to summary |
|---|---|
| public void writeEntityReference(String name) throws IOException, XMLStreamException Implements abstract com.
| |
| writePI | back to summary |
|---|---|
| public int writePI(String target, String data) throws IOException, XMLStreamException Implements abstract com.
| |
| writePIEnd | back to summary |
|---|---|
| public final void writePIEnd() throws IOException Implements abstract com.
| |
| writePIStart | back to summary |
|---|---|
| public final void writePIStart(String target, boolean addSpace) throws IOException Implements abstract com.
| |
| writePrefixedName | back to summary |
|---|---|
| protected final void writePrefixedName(String prefix, String localName) throws IOException | |
| writeRaw | back to summary |
|---|---|
| public void writeRaw(char[] cbuf, int offset, int len) throws IOException Implements abstract com.
| |
| writeRaw | back to summary |
|---|---|
| public void writeRaw(String str) throws IOException Overrides com.
| |
| writeRaw | back to summary |
|---|---|
| public void writeRaw(String str, int offset, int len) throws IOException Implements abstract com.
| |
| writeRawAscii | back to summary |
|---|---|
| public final void writeRawAscii(char[] cbuf, int offset, int len) throws IOException Implements abstract com. 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.
| |
| writeSegmentedCData | back to summary |
|---|---|
| protected void writeSegmentedCData(String content, int index) throws IOException | |
| writeSegmentedCData | back to summary |
|---|---|
| protected void writeSegmentedCData(char[] c, int start, int len, int index) throws IOException | |
| writeSegmentedComment | back to summary |
|---|---|
| protected void writeSegmentedComment(String content, int index) throws IOException | |
| writeStartTagEmptyEnd | back to summary |
|---|---|
| public void writeStartTagEmptyEnd() throws IOException Implements abstract com.
| |
| writeStartTagEnd | back to summary |
|---|---|
| public void writeStartTagEnd() throws IOException Implements abstract com.
| |
| writeStartTagStart | back to summary |
|---|---|
| public void writeStartTagStart(String localName) throws IOException, XMLStreamException Implements abstract com. Doc from com. 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)
| |
| writeStartTagStart | back to summary |
|---|---|
| public void writeStartTagStart(String prefix, String localName) throws IOException, XMLStreamException Implements abstract com. Doc from com. 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)
| |
| writeTypedAttribute | back to summary |
|---|---|
| public void writeTypedAttribute(String localName, AsciiValueEncoder enc) throws IOException, XMLStreamException Implements abstract com. Doc from com. Method similar to
| |
| writeTypedAttribute | back to summary |
|---|---|
| public void writeTypedAttribute(String prefix, String localName, AsciiValueEncoder enc) throws IOException, XMLStreamException Implements abstract com. Doc from com. Method similar to
| |
| writeTypedAttribute | back to summary |
|---|---|
| public void writeTypedAttribute(String prefix, String localName, String nsURI, AsciiValueEncoder enc, XMLValidator validator, char[] copyBuffer) throws IOException, XMLStreamException Implements abstract com. Doc from com. Method similar to
| |
| writeTypedElement | back to summary |
|---|---|
| public final void writeTypedElement(AsciiValueEncoder enc) throws IOException Implements abstract com. Doc from com. Like
| |
| writeTypedElement | back to summary |
|---|---|
| public final void writeTypedElement(AsciiValueEncoder enc, XMLValidator validator, char[] copyBuffer) throws IOException, XMLStreamException Implements abstract com. Doc from com. Like
| |
| writeXmlDeclaration | back to summary |
|---|---|
| public void writeXmlDeclaration(String version, String encoding, String standalone) throws IOException Implements abstract com.
| |