Top Description Fields Constructors Methods
com.fasterxml.aalto.util

public final Class TextBuilder

extends Object
Class Inheritance
Imports
java.io.IOException, .Writer, java.util.ArrayList, org.xml.sax.ContentHandler, .SAXException, org.xml.sax.ext.LexicalHandler, org.codehaus.stax2.typed.Base64Variant, .TypedArrayDecoder, .TypedXMLStreamException, org.codehaus.stax2.ri.typed.CharArrayBase64Decoder, com.fasterxml.aalto.in.ReaderConfig

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

Field Summary

Modifier and TypeField and Description
private final ReaderConfig
private char[]
private int
_currentSize

Number of characters in currently active (last) segment

private char[]
private int
private int
private boolean
_isIndentation

Marker to know if the contents currently stored were created using "indentation detection".

private char[]
private int
_resultLen

Indicator for length of data with _resultArray, iff the primary indicator (_currentSize) is invalid (-1).

private String
_resultString

String that will be constructed when the whole contents are needed; will be temporarily stored in case asked for again.

private ArrayList<char[]>
_segments

List of segments prior to currently active segment.

private int
_segmentSize

Amount of characters in segments in _segments

pack-priv static final int
DEF_INITIAL_BUFFER_SIZE

Size of the first text segment buffer to allocate.

pack-priv static final int
public static final int
public static final int
pack-priv static final int
private static final String
private static final char[]
private static final String[]
private static final String
private static final char[]
private static final String[]
pack-priv static final char[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private final char[]
allocBuffer(int minNeeded)

public void
append(char c)

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

public void
public void
appendSurrogate(int surr)

private char[]
private int
calcNewSize(int latestSize)

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

public static TextBuilder
public int
decodeElements(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.

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.

private void
expand(int roomNeeded)

Method called when current segment is full, to allocate new segment.

public char[]
public 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

public void
public void
public char[]
public int
public char[]
public boolean
public int
rawContentsTo(Writer w)

Method that will stream contents of this buffer into specified Writer.

public void
recycle(boolean force)

Method called to indicate that the underlying buffers should now be recycled if they haven't yet been recycled.

public void
resetForBinaryDecode(Base64Variant v, CharArrayBase64Decoder dec, boolean firstChunk)

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

private final void
public void
resetWithChar(char c)

Method called to initialize the buffer with just a single char

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.

public void
resetWithIndentation(int indCharCount, char indChar)

public void
public void
public int

Returns:

Number of characters currently stored by this collector
size
()

public String
toString()

Overrides java.lang.Object.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)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_configback to summary
private final ReaderConfig _config
_currentSegmentback to summary
private char[] _currentSegment
_currentSizeback to summary
private int _currentSize

Number of characters in currently active (last) segment

_decodeBufferback to summary
private char[] _decodeBuffer
_decodeEndback to summary
private int _decodeEnd
_decodePtrback to summary
private int _decodePtr
_isIndentationback to summary
private boolean _isIndentation

Marker to know if the contents currently stored were created using "indentation detection". If so, it's known to be all white space

_resultArrayback to summary
private char[] _resultArray
_resultLenback to summary
private int _resultLen

Indicator for length of data with _resultArray, iff the primary indicator (_currentSize) is invalid (-1).

_resultStringback to summary
private String _resultString

String that will be constructed when the whole contents are needed; will be temporarily stored in case asked for again.

_segmentsback to summary
private ArrayList<char[]> _segments

List of segments prior to currently active segment.

_segmentSizeback to summary
private int _segmentSize

Amount of characters in segments in _segments

DEF_INITIAL_BUFFER_SIZEback to summary
pack-priv static final int DEF_INITIAL_BUFFER_SIZE

Size of the first text segment buffer to allocate. Need not contain the biggest segment, since new ones will get allocated as needed. However, it's sensible to use something that often is big enough to contain typical segments.

INT_SPACEback to summary
pack-priv static final int INT_SPACE
MAX_INDENT_SPACESback to summary
public static final int MAX_INDENT_SPACES
MAX_INDENT_TABSback to summary
public static final int MAX_INDENT_TABS
MAX_SEGMENT_LENGTHback to summary
pack-priv static final int MAX_SEGMENT_LENGTH
sIndSpacesback to summary
private static final String sIndSpaces
sIndSpacesArrayback to summary
private static final char[] sIndSpacesArray
sIndSpacesStringsback to summary
private static final String[] sIndSpacesStrings
sIndTabsback to summary
private static final String sIndTabs
sIndTabsArrayback to summary
private static final char[] sIndTabsArray
sIndTabsStringsback to summary
private static final String[] sIndTabsStrings
sNoCharsback to summary
pack-priv static final char[] sNoChars

Constructor Detail

TextBuilderback to summary
private TextBuilder(ReaderConfig cfg)

Method Detail

allocBufferback to summary
private final char[] allocBuffer(int minNeeded)
appendback to summary
public void append(char c)
appendback to summary
public void append(char[] c, int start, int len)
appendback to summary
public void append(String str)
appendSurrogateback to summary
public void appendSurrogate(int surr)
buildResultArrayback to summary
private char[] buildResultArray()
calcNewSizeback to summary
private int calcNewSize(int latestSize)
contentsAsArrayback to summary
public char[] contentsAsArray()
contentsAsStringback to summary
public String contentsAsString()
contentsToArrayback to summary
public int contentsToArray(int srcStart, char[] dst, int dstStart, int len)
createRecyclableBufferback to summary
public static TextBuilder createRecyclableBuffer(ReaderConfig cfg)
decodeElementsback to summary
public int decodeElements(TypedArrayDecoder tad, boolean reset) throws 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.

equalsStringback to summary
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.

expandback to summary
private void expand(int roomNeeded)

Method called when current segment is full, to allocate new segment.

finishCurrentSegmentback to summary
public char[] finishCurrentSegment()
fireSaxCharacterEventsback to summary
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

fireSaxCommentEventback to summary
public void fireSaxCommentEvent(LexicalHandler h) throws SAXException
fireSaxSpaceEventsback to summary
public void fireSaxSpaceEvents(ContentHandler h) throws SAXException
getBufferWithoutResetback to summary
public char[] getBufferWithoutReset()
getCurrentLengthback to summary
public int getCurrentLength()
getTextBufferback to summary
public char[] getTextBuffer()
isAllWhitespaceback to summary
public boolean isAllWhitespace()
rawContentsToback to summary
public int rawContentsTo(Writer w) throws IOException

Method that will stream contents of this buffer into specified Writer.

recycleback to summary
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.

resetForBinaryDecodeback to summary
public void resetForBinaryDecode(Base64Variant v, CharArrayBase64Decoder dec, boolean firstChunk)

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

resetForDecodeback to summary
private final void resetForDecode()
resetWithCharback to summary
public void resetWithChar(char c)

Method called to initialize the buffer with just a single char

resetWithEmptyback to summary
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.

resetWithIndentationback to summary
public void resetWithIndentation(int indCharCount, char indChar)
resetWithSurrogateback to summary
public void resetWithSurrogate(int c)
setCurrentLengthback to summary
public void setCurrentLength(int len)
sizeback to summary
public int size()
Returns:int

Number of characters currently stored by this collector

toStringback to summary
public String toString()

Overrides java.lang.Object.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)

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override