Class BufferingXmlWriter

java.lang.Object
com.ctc.wstx.sw.XmlWriter
com.ctc.wstx.sw.BufferingXmlWriter
All Implemented Interfaces:
XMLStreamConstants

public final class BufferingXmlWriter extends XmlWriter implements XMLStreamConstants
Concrete implementation of 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.

  • Field Details

    • DEFAULT_BUFFER_SIZE

      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.
      See Also:
    • DEFAULT_SMALL_SIZE

      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.
      See Also:
    • HIGHEST_ENCODABLE_ATTR_CHAR

      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.
      See Also:
    • HIGHEST_ENCODABLE_TEXT_CHAR

      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.
      See Also:
    • QUOTABLE_TEXT_CHARS

      protected static final int[] QUOTABLE_TEXT_CHARS
    • mOut

      protected final Writer mOut
      Actual Writer to use for outputting buffered data as appropriate.
    • mOutputBuffer

      protected char[] mOutputBuffer
    • mSmallWriteSize

      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.
    • mOutputPtr

      protected int mOutputPtr
    • mOutputBufLen

      protected int mOutputBufLen
    • mUnderlyingStream

      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.
    • mEncHighChar

      private final int mEncHighChar
      First Unicode character (one with lowest value) after (and including) which character entities have to be used. For
    • mEncQuoteChar

      final char mEncQuoteChar
      Character that is considered to be the enclosing quote character; for XML either single or double quote.
    • mEncQuoteEntity

      final String mEncQuoteEntity
      Entity String to use for escaping the quote character.
  • Constructor Details

    • BufferingXmlWriter

      public BufferingXmlWriter(Writer out, WriterConfig cfg, String enc, boolean autoclose, OutputStream outs, int bitsize) throws IOException
      Parameters:
      outs - Underlying OutputStream that the writer (out) is using, if known. Needed to support (optional) access to the underlying stream
      Throws:
      IOException
  • Method Details