com.fasterxml.aalto.util

## Class TextBuilder

- java.lang.Object
- - com.fasterxml.aalto.util.TextBuilder

-     public final class TextBuilder
      extends Object

  Class conceptually similar to `StringBuilder`, but that allows for bit more efficient building, using segmented internal buffers, and direct access to these buffers.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `MAX_INDENT_SPACES`
    `static int` | `MAX_INDENT_TABS`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `append(char c)`
    `void` | `append(char[] c, int start, int len)`
    `void` | `append(String str)`
    `void` | `appendSurrogate(int surr)`
    `char[]` | `contentsAsArray()`
    `String` | `contentsAsString()`
    `int` | `contentsToArray(int srcStart, char[] dst, int dstStart, int len)`
    `static TextBuilder` | `createRecyclableBuffer(ReaderConfig cfg)`
    `int` | `decodeElements(org.codehaus.stax2.typed.TypedArrayDecoder tad, boolean reset)` Method called by the stream reader to decode space-separated tokens that are part of the current text event (contents of which are stored within this buffer), using given decoder.
    `boolean` | `endsWith(String str)` Method that can be used to check if the contents of the buffer end in specified String.
    `boolean` | `equalsString(String str)` Note: it is assumed that this method is not used often enough to be a bottleneck, or for long segments.
    `char[]` | `finishCurrentSegment()`
    `void` | `fireSaxCharacterEvents(ContentHandler h)` This is a specialized "accessor" method, which is basically to fire SAX characters() events in an optimal way, based on which internal buffers are being used
    `void` | `fireSaxCommentEvent(LexicalHandler h)`
    `void` | `fireSaxSpaceEvents(ContentHandler h)`
    `char[]` | `getBufferWithoutReset()`
    `int` | `getCurrentLength()`
    `char[]` | `getTextBuffer()`
    `boolean` | `isAllWhitespace()`
    `int` | `rawContentsTo(Writer w)` Method that will stream contents of this buffer into specified Writer.
    `void` | `recycle(boolean force)` Method called to indicate that the underlying buffers should now be recycled if they haven't yet been recycled.
    `void` | `resetForBinaryDecode(org.codehaus.stax2.typed.Base64Variant v, org.codehaus.stax2.ri.typed.CharArrayBase64Decoder dec, boolean firstChunk)` Method called to initialize given base64 decoder with data contained in this text buffer (for the current event).
    `void` | `resetWithChar(char c)` Method called to initialize the buffer with just a single char
    `char[]` | `resetWithEmpty()` Method called to clear out any content text buffer may have, and initializes and returns the first segment to add characters to.
    `void` | `resetWithIndentation(int indCharCount, char indChar)`
    `void` | `resetWithSurrogate(int c)`
    `void` | `setCurrentLength(int len)`
    `int` | `size()`
    `String` | `toString()` Note: calling this method may not be as efficient as calling `contentsAsString()`, since it is guaranteed that resulting String is NOT cached (to ensure we see no stale data)

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### MAX_INDENT_SPACES

          public static final int MAX_INDENT_SPACES

      See Also:
        Constant Field Values

    - #### MAX_INDENT_TABS

          public static final int MAX_INDENT_TABS

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### createRecyclableBuffer

          public static TextBuilder createRecyclableBuffer(ReaderConfig cfg)

    - #### recycle

          public void recycle(boolean force)

      Method called to indicate that the underlying buffers should now be recycled if they haven't yet been recycled. Although caller can still use this text buffer, it is not advisable to call this method if that is likely, since next time a buffer is needed, buffers need to reallocated. Note: calling this method automatically also clears contents of the buffer.

    - #### resetWithEmpty

          public char[] resetWithEmpty()

      Method called to clear out any content text buffer may have, and initializes and returns the first segment to add characters to.

    - #### resetWithIndentation

          public void resetWithIndentation(int indCharCount,
                                  char indChar)

    - #### resetWithChar

          public void resetWithChar(char c)

      Method called to initialize the buffer with just a single char

    - #### resetWithSurrogate

          public void resetWithSurrogate(int c)

    - #### getBufferWithoutReset

          public char[] getBufferWithoutReset()

    - #### size

          public int size()

      Returns:
        Number of characters currently stored by this collector

    - #### getTextBuffer

          public char[] getTextBuffer()

    - #### contentsAsString

          public String contentsAsString()

    - #### contentsAsArray

          public char[] contentsAsArray()

    - #### contentsToArray

          public int contentsToArray(int srcStart,
                            char[] dst,
                            int dstStart,
                            int len)

    - #### rawContentsTo

          public int rawContentsTo(Writer w)
                            throws IOException

      Method that will stream contents of this buffer into specified Writer.
      Throws:
        `IOException`

    - #### isAllWhitespace

          public boolean isAllWhitespace()

    - #### endsWith

          public boolean endsWith(String str)

      Method that can be used to check if the contents of the buffer end in specified String.
      Returns:
        True if the textual content buffer contains ends with the specified String; false otherwise

    - #### equalsString

          public boolean equalsString(String str)

      Note: it is assumed that this method is not used often enough to be a bottleneck, or for long segments. Based on this, it is optimized for common simple cases where there is only one single character segment to use; fallback for other cases is to create such segment.

    - #### fireSaxCharacterEvents

          public void fireSaxCharacterEvents(ContentHandler h)
                                      throws SAXException

      This is a specialized "accessor" method, which is basically to fire SAX characters() events in an optimal way, based on which internal buffers are being used
      Throws:
        `SAXException`

    - #### fireSaxSpaceEvents

          public void fireSaxSpaceEvents(ContentHandler h)
                                  throws SAXException

      Throws:
        `SAXException`

    - #### fireSaxCommentEvent

          public void fireSaxCommentEvent(LexicalHandler h)
                                   throws SAXException

      Throws:
        `SAXException`

    - #### append

          public void append(char c)

    - #### appendSurrogate

          public void appendSurrogate(int surr)

    - #### append

          public void append(char[] c,
                    int start,
                    int len)

    - #### append

          public void append(String str)

    - #### getCurrentLength

          public int getCurrentLength()

    - #### setCurrentLength

          public void setCurrentLength(int len)

    - #### finishCurrentSegment

          public char[] finishCurrentSegment()

    - #### decodeElements

          public int decodeElements(org.codehaus.stax2.typed.TypedArrayDecoder tad,
                           boolean reset)
                             throws org.codehaus.stax2.typed.TypedXMLStreamException

      Method called by the stream reader to decode space-separated tokens that are part of the current text event (contents of which are stored within this buffer), using given decoder.
      Throws:
        `org.codehaus.stax2.typed.TypedXMLStreamException`

    - #### resetForBinaryDecode

          public void resetForBinaryDecode(org.codehaus.stax2.typed.Base64Variant v,
                                  org.codehaus.stax2.ri.typed.CharArrayBase64Decoder dec,
                                  boolean firstChunk)

      Method called to initialize given base64 decoder with data contained in this text buffer (for the current event).

    - #### toString

          public String toString()

      Note: calling this method may not be as efficient as calling `contentsAsString()`, since it is guaranteed that resulting String is NOT cached (to ensure we see no stale data)
      Overrides:
        `toString` in class `Object`

Copyright © 2012-2015 FasterXML. All Rights Reserved.