public final class

TextBuffer

extends Object
java.lang.Object
   ↳ com.fasterxml.jackson.core.util.TextBuffer

Class Overview

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.

Summary

Public Constructors
TextBuffer(BufferRecycler allocator)
Public Methods
void append(char[] c, int start, int len)
void append(char c)
void append(String str, int offset, int len)
char[] contentsAsArray()
BigDecimal contentsAsDecimal()
Convenience method for converting contents of the buffer into a BigDecimal.
double contentsAsDouble()
Convenience method for converting contents of the buffer into a Double value.
String contentsAsString()
final char[] emptyAndGetCurrentSegment()
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[] expandCurrentSegment()
Method called to expand size of the current segment, to accomodate for more contiguous content.
char[] finishCurrentSegment()
char[] getCurrentSegment()
int getCurrentSegmentSize()
char[] getTextBuffer()
int getTextOffset()
boolean hasTextAsCharacters()
Method that can be used to check whether textual contents can be efficiently accessed using getTextBuffer().
void releaseBuffers()
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 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 resetWithString(String value)
void setCurrentLength(int len)
int size()
String toString()
Note: calling this method may not be as efficient as calling contentsAsString(), since it's not guaranteed that resulting String is cached.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public TextBuffer (BufferRecycler allocator)

Public Methods

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

public void append (char c)

public void append (String str, int offset, int len)

public char[] contentsAsArray ()

public BigDecimal contentsAsDecimal ()

Convenience method for converting contents of the buffer into a BigDecimal.

public double contentsAsDouble ()

Convenience method for converting contents of the buffer into a Double value.

public String contentsAsString ()

public final char[] emptyAndGetCurrentSegment ()

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

public char[] finishCurrentSegment ()

public char[] getCurrentSegment ()

public int getCurrentSegmentSize ()

public char[] getTextBuffer ()

public int getTextOffset ()

public boolean hasTextAsCharacters ()

Method that can be used to check whether textual contents can be efficiently accessed using getTextBuffer().

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.

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

public void resetWithEmpty ()

Method called to clear out any content text buffer may have, and initializes buffer to use non-shared data.

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

public void resetWithString (String value)

public void setCurrentLength (int len)

public int size ()

Returns
  • Number of characters currently stored by this collector

public String toString ()

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