Package org.codehaus.jackson.util
Class TextBuffer
java.lang.Object
org.codehaus.jackson.util.TextBuffer
TextBuffer is a class similar to
StringBuffer
, with
following differences:
- TextBuffer uses segments character arrays, to avoid having to do additional array copies when array is not big enough. This means that only reallocating that is necessary is done only once: if and when caller wants to access contents in a linear array (char[], String).
- TextBuffer can also be initialized in "shared mode", in which it will just act as a wrapper to a single char array managed by another object (like parser that owns it)
- TextBuffer is not synchronized.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(char c) void
append
(char[] c, int start, int len) void
char[]
Convenience method for converting contents of the buffer into aBigDecimal
.double
Convenience method for converting contents of the buffer into a Double value.final char[]
void
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[]
Method called to expand size of the current segment, to accomodate for more contiguous content.char[]
char[]
int
char[]
int
boolean
Method that can be used to check whether textual contents can be efficiently accessed usinggetTextBuffer()
.void
Method called to indicate that the underlying buffers should now be recycled if they haven't yet been recycled.void
resetWithCopy
(char[] buf, int start, int len) void
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
resetWithString
(String value) void
setCurrentLength
(int len) int
size()
toString()
Note: calling this method may not be as efficient as callingcontentsAsString()
, since it's not guaranteed that resulting String is cached.
-
Constructor Details
-
TextBuffer
-
-
Method Details
-
releaseBuffers
public void releaseBuffers()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. -
resetWithCopy
public void resetWithCopy(char[] buf, int start, int len) -
resetWithString
-
size
public int size()- Returns:
- Number of characters currently stored by this collector
-
getTextOffset
public int getTextOffset() -
hasTextAsCharacters
public boolean hasTextAsCharacters()Method that can be used to check whether textual contents can be efficiently accessed usinggetTextBuffer()
.- Since:
- 1.9
-
getTextBuffer
public char[] getTextBuffer() -
contentsAsString
-
contentsAsArray
public char[] contentsAsArray() -
contentsAsDecimal
Convenience method for converting contents of the buffer into aBigDecimal
.- Throws:
NumberFormatException
-
contentsAsDouble
Convenience method for converting contents of the buffer into a Double value.- Throws:
NumberFormatException
-
append
public void append(char c) -
append
public void append(char[] c, int start, int len) -
append
-
getCurrentSegment
public char[] getCurrentSegment() -
emptyAndGetCurrentSegment
public final char[] emptyAndGetCurrentSegment() -
getCurrentSegmentSize
public int getCurrentSegmentSize() -
setCurrentLength
public void setCurrentLength(int len) -
finishCurrentSegment
public char[] finishCurrentSegment() -
expandCurrentSegment
public char[] expandCurrentSegment()Method called to expand size of the current segment, to accomodate for more contiguous content. Usually only used when parsing tokens like names. -
toString
Note: calling this method may not be as efficient as callingcontentsAsString()
, since it's not guaranteed that resulting String is cached.
-