com.ctc.wstx.util
Class TextBuffer

java.lang.Object
  extended by com.ctc.wstx.util.TextBuffer

public final class TextBuffer
extends java.lang.Object

TextBuffer is a class similar to StringBuffer, with following differences:

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.


Field Summary
static int MAX_INDENT_SPACES
           
static int MAX_INDENT_TABS
           
 
Method Summary
 void append(char c)
           
 void append(char[] c, int start, int len)
           
 void append(java.lang.String str)
           
 char[] contentsAsArray()
           
 java.lang.String contentsAsString()
           
 int contentsToArray(int srcStart, char[] dst, int dstStart, int len)
           
static TextBuffer createRecyclableBuffer(ReaderConfig cfg)
           
static TextBuffer createTemporaryBuffer(int initialSize)
           
 boolean endsWith(java.lang.String str)
          Method that can be used to check if the contents of the buffer end in specified String.
 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.
 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.
 char[] finishCurrentSegment()
           
 void fireDtdCommentEvent(DTDEventListener l)
           
 void fireSaxCharacterEvents(org.xml.sax.ContentHandler h)
           
 void fireSaxCommentEvent(org.xml.sax.ext.LexicalHandler h)
           
 void fireSaxSpaceEvents(org.xml.sax.ContentHandler h)
           
 char[] getCurrentSegment()
           
 int getCurrentSegmentSize()
           
 char[] getTextBuffer()
           
 int getTextStart()
           
 boolean isAllWhitespace()
           
 int rawContentsTo(java.io.Writer w)
          Method that will stream contents of this buffer into specified Writer.
 java.io.Reader rawContentsViaReader()
           
 void recycle(boolean force)
          Method called to indicate that the underlying buffers should now be recycled if they haven't yet been recycled.
 void resetInitialized()
          Method called to make sure there is a non-shared segment to use, without appending any content yet.
 void resetWithCopy(char[] buf, int start, int len)
           
 void resetWithEmpty()
          Method called to clear out any content text buffer may have, and initializes buffer to use non-shared data.
 void resetWithIndentation(int indCharCount, char indChar)
           
 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.
 void setCurrentLength(int len)
           
 int size()
           
 java.lang.String toString()
          Note: calling this method may not be as efficient as calling contentsAsString(), since it's not guaranteed that resulting String is cached.
 void unshare(int needExtra)
          Method called if/when we need to append content when we have been initialized to use shared buffer.
 void validateText(XMLValidator vld, boolean lastSegment)
           
 
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 TextBuffer createRecyclableBuffer(ReaderConfig cfg)

createTemporaryBuffer

public static TextBuffer createTemporaryBuffer(int initialSize)

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 void resetWithEmpty()
Method called to clear out any content text buffer may have, and initializes buffer to use non-shared data.


resetWithShared

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).


resetWithCopy

public void resetWithCopy(char[] buf,
                          int start,
                          int len)

resetInitialized

public void resetInitialized()
Method called to make sure there is a non-shared segment to use, without appending any content yet.


resetWithIndentation

public void resetWithIndentation(int indCharCount,
                                 char indChar)

size

public int size()
Returns:
Number of characters currently stored by this collector

getTextStart

public int getTextStart()

getTextBuffer

public char[] getTextBuffer()

contentsAsString

public java.lang.String contentsAsString()

contentsAsArray

public char[] contentsAsArray()

contentsToArray

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

rawContentsTo

public int rawContentsTo(java.io.Writer w)
                  throws java.io.IOException
Method that will stream contents of this buffer into specified Writer.

Throws:
java.io.IOException

rawContentsViaReader

public java.io.Reader rawContentsViaReader()
                                    throws java.io.IOException
Throws:
java.io.IOException

isAllWhitespace

public boolean isAllWhitespace()

endsWith

public boolean endsWith(java.lang.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(java.lang.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(org.xml.sax.ContentHandler h)
                            throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

fireSaxSpaceEvents

public void fireSaxSpaceEvents(org.xml.sax.ContentHandler h)
                        throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

fireSaxCommentEvent

public void fireSaxCommentEvent(org.xml.sax.ext.LexicalHandler h)
                         throws org.xml.sax.SAXException
Throws:
org.xml.sax.SAXException

fireDtdCommentEvent

public void fireDtdCommentEvent(DTDEventListener l)

validateText

public void validateText(XMLValidator vld,
                         boolean lastSegment)
                  throws XMLValidationException
Throws:
XMLValidationException

ensureNotShared

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.


append

public void append(char c)

append

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

append

public void append(java.lang.String str)

getCurrentSegment

public char[] getCurrentSegment()

getCurrentSegmentSize

public int getCurrentSegmentSize()

setCurrentLength

public void setCurrentLength(int len)

finishCurrentSegment

public char[] finishCurrentSegment()

toString

public java.lang.String toString()
Note: calling this method may not be as efficient as calling contentsAsString(), since it's not guaranteed that resulting String is cached.

Overrides:
toString in class java.lang.Object

unshare

public void unshare(int needExtra)
Method called if/when we need to append content when we have been initialized to use shared buffer.