StringBuilder, with
following differences:
Over time more and more cruft has accumulated here, mostly to support efficient access to collected text. Since access is easiest to do efficiently using callbacks, this class now needs to known interfaces of SAX classes and validators.
Notes
about usage: for debugging purposes, it's suggested to use
toString method, as opposed to
contentsAsArray or contentsAsString. Internally
resulting code paths may or may not be different, WRT caching.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| 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. |
| pack-priv static final int | |
| public static final int | |
| public static final int | |
| pack-priv static final int | MAX_SEGMENT_LENGTH
We will also restrict maximum length of individual segments to allocate (not including cases where we must return a single segment). |
| private final ReaderConfig | |
| private char[] | |
| private int | mCurrentSize
Number of characters in currently active (last) segment |
| private boolean | |
| private char[] | mInputBuffer
Shared input buffer; stored here in case some input can be returned as is, without being copied to collector's own buffers. |
| private int | mInputLen
When using shared buffer, offset after the last character in shared buffer |
| private int | mInputStart
Character offset of first char in input buffer; -1 to indicate that input buffer currently does not contain any useful char data |
| private char[] | |
| private String | mResultString
String that will be constructed when the whole contents are needed; will be temporarily stored in case asked for again. |
| private ArrayList | mSegments
List of segments prior to currently active segment. |
| private int | mSegmentSize
Amount of characters in segments in |
| private static final String | |
| private static final char[] | |
| private static final String[] | |
| private static final String | |
| private static final char[] | |
| private static final String[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private final char[] | |
| public void | |
| public void | |
| public void | |
| private char[] | |
| private int | calcNewSize(int latestSize)
Method used to determine size of the next segment to allocate to contain textual content. |
| private final void | |
| public char[] | |
| public String | |
| public StringBuilder | contentsAsStringBuilder(int
Number of extra characters to preserve in StringBuilder
beyond space immediately needed to hold the contents extraSpace)Similar to |
| public int | |
| public void | |
| public static TextBuffer | |
| public static TextBuffer | |
| public void | decode(TypedValueDecoder tvd)
Generic pass-through method which call given decoder with accumulated data |
| public int | Returns: Number of tokens decoded; 0 means that no (more) tokens were found from this buffer.Pass-through decode method called to find find the next token, decode it, and repeat the process as long as there are more tokens and the array decoder accepts more entries. |
| public void | ensureNotShared()
Method called to make sure that buffer is not using shared input buffer; if it is, it will copy such contents to private buffer. |
| 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
Number of characters that the resulting
new buffer must have roomNeeded)Method called when current segment is full, to allocate new segment. |
| public char[] | |
| public void | |
| public void | |
| public void | |
| public void | |
| public char[] | |
| public int | |
| public char[] | |
| public int | |
| public void | initBinaryChunks(Base64Variant v, CharArrayBase64Decoder
Decoder that will need data dec, boolean Whether this is the first segment fed or not;
if it is, state needs to be fullt reset; if not, only partially. firstChunk)Method that needs to be called to configure given base64 decoder with textual contents collected by this buffer. |
| public boolean | |
| public int | |
| public Reader | |
| 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 | resetInitialized()
Method called to make sure there is a non-shared segment to use, without appending any content yet. |
| public void | |
| public void | resetWithEmpty()
Method called to clear out any content text buffer may have, and initializes buffer to use non-shared data. |
| public void | resetWithEmptyString()
Similar to |
| public void | |
| public void | resetWithShared(char[] buf, int start, int len)
Method called to initialize the buffer with a shared copy of data; this means that buffer will just have pointers to actual data. |
| public void | |
| public int | |
| public String | toString()
Overrides java. Note calling this method may not be as efficient as calling
|
| public void | unshare(int needExtra)
Method called if/when we need to append content when we have been initialized to use shared buffer. |
| public void |
| DEF_INITIAL_BUFFER_SIZE | back 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 segments. | |
| INT_SPACE | back to summary |
|---|---|
| pack-priv static final int INT_SPACE | |
| MAX_INDENT_SPACES | back to summary |
|---|---|
| public static final int MAX_INDENT_SPACES | |
| MAX_INDENT_TABS | back to summary |
|---|---|
| public static final int MAX_INDENT_TABS | |
| MAX_SEGMENT_LENGTH | back to summary |
|---|---|
| pack-priv static final int MAX_SEGMENT_LENGTH We will also restrict maximum length of individual segments to allocate (not including cases where we must return a single segment). Value is somewhat arbitrary, let's use it so that memory used is no more than 1/2 megabytes. | |
| mConfig | back to summary |
|---|---|
| private final ReaderConfig mConfig | |
| mCurrentSegment | back to summary |
|---|---|
| private char[] mCurrentSegment | |
| mCurrentSize | back to summary |
|---|---|
| private int mCurrentSize Number of characters in currently active (last) segment | |
| mHasSegments | back to summary |
|---|---|
| private boolean mHasSegments | |
| mInputBuffer | back to summary |
|---|---|
| private char[] mInputBuffer Shared input buffer; stored here in case some input can be returned as is, without being copied to collector's own buffers. Note that this is read-only for this Objet. | |
| mInputLen | back to summary |
|---|---|
| private int mInputLen When using shared buffer, offset after the last character in shared buffer | |
| mInputStart | back to summary |
|---|---|
| private int mInputStart Character offset of first char in input buffer; -1 to indicate that input buffer currently does not contain any useful char data | |
| mResultArray | back to summary |
|---|---|
| private char[] mResultArray | |
| mResultString | back to summary |
|---|---|
| private String mResultString String that will be constructed when the whole contents are needed; will be temporarily stored in case asked for again. | |
| mSegments | back to summary |
|---|---|
| private ArrayList<char[]> mSegments List of segments prior to currently active segment. | |
| mSegmentSize | back to summary |
|---|---|
| private int mSegmentSize Amount of characters in segments in | |
| sIndSpaces | back to summary |
|---|---|
| private static final String sIndSpaces | |
| sIndSpacesArray | back to summary |
|---|---|
| private static final char[] sIndSpacesArray | |
| sIndSpacesStrings | back to summary |
|---|---|
| private static final String[] sIndSpacesStrings | |
| sIndTabs | back to summary |
|---|---|
| private static final String sIndTabs | |
| sIndTabsArray | back to summary |
|---|---|
| private static final char[] sIndTabsArray | |
| sIndTabsStrings | back to summary |
|---|---|
| private static final String[] sIndTabsStrings | |
| TextBuffer | back to summary |
|---|---|
| private TextBuffer(ReaderConfig cfg) | |
| allocBuffer | back to summary |
|---|---|
| private final char[] allocBuffer(int needed) | |
| append | back to summary |
|---|---|
| public void append(char c) | |
| append | back to summary |
|---|---|
| public void append(char[] c, int start, int len) | |
| append | back to summary |
|---|---|
| public void append(String str) | |
| buildResultArray | back to summary |
|---|---|
| private char[] buildResultArray() | |
| calcNewSize | back to summary |
|---|---|
| private int calcNewSize(int latestSize) Method used to determine size of the next segment to allocate to contain textual content. | |
| clearSegments | back to summary |
|---|---|
| private final void clearSegments() | |
| contentsAsArray | back to summary |
|---|---|
| public char[] contentsAsArray() | |
| contentsAsString | back to summary |
|---|---|
| public String contentsAsString() | |
| contentsAsStringBuilder | back to summary |
|---|---|
| public StringBuilder contentsAsStringBuilder(int extraSpace) Similar to
| |
| contentsToArray | back to summary |
|---|---|
| public int contentsToArray(int srcStart, char[] dst, int dstStart, int len) | |
| contentsToStringBuilder | back to summary |
|---|---|
| public void contentsToStringBuilder(StringBuilder sb) | |
| createRecyclableBuffer | back to summary |
|---|---|
| public static TextBuffer createRecyclableBuffer(ReaderConfig cfg) | |
| createTemporaryBuffer | back to summary |
|---|---|
| public static TextBuffer createTemporaryBuffer() | |
| decode | back to summary |
|---|---|
| public void decode(TypedValueDecoder tvd) throws IllegalArgumentException Generic pass-through method which call given decoder with accumulated data | |
| decodeElements | back to summary |
|---|---|
| public int decodeElements(TypedArrayDecoder tad, InputProblemReporter rep) throws TypedXMLStreamException Pass-through decode method called to find find the next token, decode it, and repeat the process as long as there are more tokens and the array decoder accepts more entries. All tokens processed will be "consumed", such that they will not be visible via buffer.
| |
| ensureNotShared | back to summary |
|---|---|
| public void ensureNotShared() Method called to make sure that buffer is not using shared input buffer; if it is, it will copy such contents to private buffer. | |
| equalsString | back 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. | |
| expand | back to summary |
|---|---|
| private void expand(int roomNeeded) Method called when current segment is full, to allocate new segment.
| |
| finishCurrentSegment | back to summary |
|---|---|
| public char[] finishCurrentSegment() | |
| fireDtdCommentEvent | back to summary |
|---|---|
| public void fireDtdCommentEvent(DTDEventListener l) | |
| fireSaxCharacterEvents | back to summary |
|---|---|
| public void fireSaxCharacterEvents(ContentHandler h) throws SAXException | |
| fireSaxCommentEvent | back to summary |
|---|---|
| public void fireSaxCommentEvent(LexicalHandler h) throws SAXException | |
| fireSaxSpaceEvents | back to summary |
|---|---|
| public void fireSaxSpaceEvents(ContentHandler h) throws SAXException | |
| getCurrentSegment | back to summary |
|---|---|
| public char[] getCurrentSegment() | |
| getCurrentSegmentSize | back to summary |
|---|---|
| public int getCurrentSegmentSize() | |
| getTextBuffer | back to summary |
|---|---|
| public char[] getTextBuffer() | |
| getTextStart | back to summary |
|---|---|
| public int getTextStart() | |
| initBinaryChunks | back to summary |
|---|---|
| public void initBinaryChunks(Base64Variant v, CharArrayBase64Decoder dec, boolean firstChunk) Method that needs to be called to configure given base64 decoder with textual contents collected by this buffer.
| |
| isAllWhitespace | back to summary |
|---|---|
| public boolean isAllWhitespace() | |
| rawContentsTo | back to summary |
|---|---|
| public int rawContentsTo(Writer w) throws IOException Method that will stream contents of this buffer into specified Writer. | |
| rawContentsViaReader | back to summary |
|---|---|
| public Reader rawContentsViaReader() throws IOException
Deprecated
| |
| recycle | back 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. | |
| resetInitialized | back to summary |
|---|---|
| public void resetInitialized() Method called to make sure there is a non-shared segment to use, without appending any content yet. | |
| resetWithCopy | back to summary |
|---|---|
| public void resetWithCopy(char[] buf, int start, int len) | |
| resetWithEmpty | back to summary |
|---|---|
| public void resetWithEmpty() Method called to clear out any content text buffer may have, and initializes buffer to use non-shared data. | |
| resetWithEmptyString | back to summary |
|---|---|
| public void resetWithEmptyString() Similar to | |
| resetWithIndentation | back to summary |
|---|---|
| public void resetWithIndentation(int indCharCount, char indChar) | |
| resetWithShared | back to summary |
|---|---|
| public void resetWithShared(char[] buf, int start, int len) Method called to initialize the buffer with a shared copy of data; this means that buffer will just have pointers to actual data. It also means that if anything is to be appended to the buffer, it will first have to unshare it (make a local copy). | |
| setCurrentLength | back to summary |
|---|---|
| public void setCurrentLength(int len) | |
| size | back to summary |
|---|---|
public int size()
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Note calling this method may not be as efficient as calling
| |
| unshare | back to summary |
|---|---|
| public void unshare(int needExtra) Method called if/when we need to append content when we have been initialized to use shared buffer. | |
| validateText | back to summary |
|---|---|
| public void validateText(XMLValidator vld, boolean lastSegment) throws XMLStreamException | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final int | |
| pack-priv int | |
| pack-priv char[] | |
| pack-priv int | |
| pack-priv int | |
| pack-priv ArrayList |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements abstract java. Implements java. Closes the stream and releases any system resources associated with it. |
| public void | mark(int
Limit on the number of characters that may be
read while still preserving the mark. After
reading this many characters, attempting to
reset the stream may fail. x)Overrides java. Marks the present position in the stream. |
| public boolean | markSupported()
Overrides java. Tells whether this stream supports the mark() operation. |
| public int | read(char[]
Destination buffer cbuf, int Offset at which to start storing characters offset, int Maximum number of characters to read len)Implements abstract java. Reads characters into a portion of an array. |
| public boolean | |
| public void | |
| public long |
| _currentLength | back to summary |
|---|---|
| pack-priv final int _currentLength | |
| _currentOffset | back to summary |
|---|---|
| pack-priv int _currentOffset | |
| _currentSegment | back to summary |
|---|---|
| pack-priv char[] _currentSegment | |
| _segmentIndex | back to summary |
|---|---|
| pack-priv int _segmentIndex | |
| _segmentOffset | back to summary |
|---|---|
| pack-priv int _segmentOffset | |
| _segments | back to summary |
|---|---|
| pack-priv ArrayList<char[]> _segments | |
| BufferReader | back to summary |
|---|---|
| public BufferReader(ArrayList<char[]> segs, char[] currSeg, int currSegLen) | |
| close | back to summary |
|---|---|
| public void close() Implements abstract java. Implements java. Doc from java. Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.
| |
| mark | back to summary |
|---|---|
| public void mark(int x) throws IOException Overrides java. Doc from java. Marks the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point. Not all character-input streams support the mark() operation.
| |
| markSupported | back to summary |
|---|---|
| public boolean markSupported() Overrides java. Doc from java. Tells whether this stream supports the mark() operation. The default implementation always returns false. Subclasses should override this method.
| |
| read | back to summary |
|---|---|
| public int read(char[] cbuf, int offset, int len) Implements abstract java. Doc from java. Reads characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached. If
| |
| ready | back to summary |
|---|---|
| public boolean ready() Overrides java. Doc from java. Tells whether this stream is ready to be read.
| |
| reset | back to summary |
|---|---|
| public void reset() throws IOException Overrides java. Doc from java. Resets the stream. If the stream has been marked, then attempt to reposition it at the mark. If the stream has not been marked, then attempt to reset it in some way appropriate to the particular stream, for example by repositioning it to its starting point. Not all character-input streams support the reset() operation, and some support reset() without supporting mark().
| |
| skip | back to summary |
|---|---|
| public long skip(long amount) Overrides java. Doc from java. Skips characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached. If the stream is already at its end before this method is invoked, then no characters are skipped and zero is returned.
| |