com.ctc.wstx.util
Class TextBuffer

java.lang.Object
  extended bycom.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.


Constructor Summary
TextBuffer()
           
TextBuffer(int initialSize)
           
 
Method Summary
 void append(char c)
           
 void append(char[] c, int start, int len)
           
 void append(java.lang.String str)
           
 void clear()
          Method that can be called to clear all data; makes sure that all referenced Objects can be GC'ed.
 char[] contentsAsArray()
           
 java.lang.String contentsAsString()
           
 int contentsToArray(int srcStart, char[] dst, int dstStart, int len)
           
 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.
 char[] finishCurrentSegment()
           
 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 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextBuffer

public TextBuffer()

TextBuffer

public TextBuffer(int initialSize)
Method Detail

clear

public void clear()
Method that can be called to clear all data; makes sure that all referenced Objects can be GC'ed.


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.


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

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.


unshare

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