public final class TextBuilder
extends java.lang.Object
StringBuilder
, but
that allows for bit more efficient building, using segmented internal
buffers, and direct access to these buffers.Modifier and Type | Field and Description |
---|---|
private ReaderConfig |
_config |
private char[] |
_currentSegment |
private int |
_currentSize
Number of characters in currently active (last) segment
|
private char[] |
_decodeBuffer |
private int |
_decodeEnd |
private int |
_decodePtr |
private boolean |
_isIndentation
Marker to know if the contents currently stored were created
using "indentation detection".
|
private char[] |
_resultArray |
private int |
_resultLen
Indicator for length of data with
_resultArray , iff
the primary indicator (_currentSize) is invalid (-1). |
private java.lang.String |
_resultString
String that will be constructed when the whole contents are
needed; will be temporarily stored in case asked for again.
|
private java.util.ArrayList<char[]> |
_segments
List of segments prior to currently active segment.
|
private int |
_segmentSize
Amount of characters in segments in
_segments |
(package private) static int |
DEF_INITIAL_BUFFER_SIZE
Size of the first text segment buffer to allocate.
|
(package private) static int |
INT_SPACE |
static int |
MAX_INDENT_SPACES |
static int |
MAX_INDENT_TABS |
(package private) static int |
MAX_SEGMENT_LENGTH |
private static java.lang.String |
sIndSpaces |
private static char[] |
sIndSpacesArray |
private static java.lang.String[] |
sIndSpacesStrings |
private static java.lang.String |
sIndTabs |
private static char[] |
sIndTabsArray |
private static java.lang.String[] |
sIndTabsStrings |
(package private) static char[] |
sNoChars |
Modifier | Constructor and Description |
---|---|
private |
TextBuilder(ReaderConfig cfg) |
Modifier and Type | Method and Description |
---|---|
private char[] |
allocBuffer(int minNeeded) |
void |
append(char c) |
void |
append(char[] c,
int start,
int len) |
void |
append(java.lang.String str) |
void |
appendSurrogate(int surr) |
private char[] |
buildResultArray() |
private int |
calcNewSize(int latestSize) |
char[] |
contentsAsArray() |
java.lang.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(java.lang.String str)
Method that can be used to check if the contents of the buffer end
in specified String.
|
boolean |
equalsString(java.lang.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.
|
char[] |
finishCurrentSegment() |
void |
fireSaxCharacterEvents(org.xml.sax.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(org.xml.sax.ext.LexicalHandler h) |
void |
fireSaxSpaceEvents(org.xml.sax.ContentHandler h) |
char[] |
getBufferWithoutReset() |
int |
getCurrentLength() |
char[] |
getTextBuffer() |
boolean |
isAllWhitespace() |
int |
rawContentsTo(java.io.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).
|
private void |
resetForDecode() |
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() |
java.lang.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) |
static final char[] sNoChars
static final int DEF_INITIAL_BUFFER_SIZE
static final int MAX_SEGMENT_LENGTH
static final int INT_SPACE
private final ReaderConfig _config
private java.util.ArrayList<char[]> _segments
private int _segmentSize
_segments
private char[] _currentSegment
private int _currentSize
private java.lang.String _resultString
private char[] _resultArray
private int _resultLen
_resultArray
, iff
the primary indicator (_currentSize) is invalid (-1).private char[] _decodeBuffer
private int _decodePtr
private int _decodeEnd
private boolean _isIndentation
public static final int MAX_INDENT_SPACES
public static final int MAX_INDENT_TABS
private static final java.lang.String sIndSpaces
private static final char[] sIndSpacesArray
private static final java.lang.String[] sIndSpacesStrings
private static final java.lang.String sIndTabs
private static final char[] sIndTabsArray
private static final java.lang.String[] sIndTabsStrings
private TextBuilder(ReaderConfig cfg)
public static TextBuilder createRecyclableBuffer(ReaderConfig cfg)
public void recycle(boolean force)
public char[] resetWithEmpty()
public void resetWithIndentation(int indCharCount, char indChar)
public void resetWithChar(char c)
public void resetWithSurrogate(int c)
public char[] getBufferWithoutReset()
public int size()
public char[] getTextBuffer()
public java.lang.String contentsAsString()
public char[] contentsAsArray()
public int contentsToArray(int srcStart, char[] dst, int dstStart, int len)
public int rawContentsTo(java.io.Writer w) throws java.io.IOException
java.io.IOException
public boolean isAllWhitespace()
public boolean endsWith(java.lang.String str)
public boolean equalsString(java.lang.String str)
public void fireSaxCharacterEvents(org.xml.sax.ContentHandler h) throws org.xml.sax.SAXException
org.xml.sax.SAXException
public void fireSaxSpaceEvents(org.xml.sax.ContentHandler h) throws org.xml.sax.SAXException
org.xml.sax.SAXException
public void fireSaxCommentEvent(org.xml.sax.ext.LexicalHandler h) throws org.xml.sax.SAXException
org.xml.sax.SAXException
public void append(char c)
public void appendSurrogate(int surr)
public void append(char[] c, int start, int len)
public void append(java.lang.String str)
public int getCurrentLength()
public void setCurrentLength(int len)
public char[] finishCurrentSegment()
private int calcNewSize(int latestSize)
public int decodeElements(org.codehaus.stax2.typed.TypedArrayDecoder tad, boolean reset) throws org.codehaus.stax2.typed.TypedXMLStreamException
org.codehaus.stax2.typed.TypedXMLStreamException
public void resetForBinaryDecode(org.codehaus.stax2.typed.Base64Variant v, org.codehaus.stax2.ri.typed.CharArrayBase64Decoder dec, boolean firstChunk)
private final void resetForDecode()
public java.lang.String toString()
contentsAsString()
, since it is guaranteed that resulting
String is NOT cached (to ensure we see no stale data)toString
in class java.lang.Object
private final char[] allocBuffer(int minNeeded)
private void expand(int roomNeeded)
private char[] buildResultArray()