public class TextBuffer extends Object
StringBuffer
, with
following differences:
Modifier | Constructor and Description |
---|---|
|
TextBuffer(BufferRecycler allocator) |
protected |
TextBuffer(BufferRecycler allocator,
char[] initialSegment) |
Modifier and Type | Method and Description |
---|---|
protected void |
_reportBufferOverflow(int prev,
int curr) |
void |
append(char c) |
void |
append(char[] c,
int start,
int len) |
void |
append(String str,
int offset,
int len) |
BufferRecycler |
bufferRecycler() |
char[] |
contentsAsArray() |
BigDecimal |
contentsAsDecimal()
Deprecated.
Since 2.15 use
contentsAsDecimal(boolean) instead. |
BigDecimal |
contentsAsDecimal(boolean useFastParser) |
double |
contentsAsDouble()
Deprecated.
|
double |
contentsAsDouble(boolean useFastParser)
Convenience method for converting contents of the buffer
into a Double value.
|
float |
contentsAsFloat()
Deprecated.
|
float |
contentsAsFloat(boolean useFastParser)
Convenience method for converting contents of the buffer
into a Float value.
|
int |
contentsAsInt(boolean neg)
Specialized convenience method that will decode a 32-bit int,
of at most 9 digits (and possible leading minus sign).
|
long |
contentsAsLong(boolean neg)
Specialized convenience method that will decode a 64-bit int,
of at most 18 digits (and possible leading minus sign).
|
String |
contentsAsString()
Accessor that may be used to get the contents of this buffer as a single
String regardless of whether they were collected in a segmented
fashion or not: this typically require construction of the result String. |
int |
contentsToWriter(Writer w)
Accessor that will write buffered contents using given
Writer . |
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
accommodate for more contiguous content.
|
char[] |
expandCurrentSegment(int minSize)
Method called to expand size of the current segment, to
accommodate for more contiguous content.
|
String |
finishAndReturn(int lastSegmentEnd,
boolean trimTrailingSpaces) |
char[] |
finishCurrentSegment() |
static TextBuffer |
fromInitial(char[] initialSegment)
Factory method for constructing an instance with no allocator, and
with initial full segment.
|
char[] |
getBufferWithoutReset()
Method for accessing the currently active (last) content segment
without changing state of the buffer
|
char[] |
getCurrentSegment() |
int |
getCurrentSegmentSize() |
char[] |
getTextBuffer()
Accessor that may be used to get the contents of this buffer as a single
char[] regardless of whether they were collected in a segmented
fashion or not: this typically require allocation of the result buffer. |
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 |
resetWith(char ch)
Method for clearing out possibly existing content, and replacing them with
a single-character content (so
size() would return 1 ) |
void |
resetWithCopy(char[] buf,
int offset,
int len) |
void |
resetWithCopy(String text,
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 offset,
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) |
String |
setCurrentAndReturn(int len)
Convenience method that finishes the current active content segment
(by specifying how many characters within consists of valid content)
and aggregates and returns resulting contents (similar to a call
to
contentsAsString() ). |
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. |
protected void |
validateStringLength(int length)
Convenience method that can be used to verify that a String
of specified length does not exceed maximum specific by this
constraints object: if it does, a
JsonParseException
is thrown. |
public TextBuffer(BufferRecycler allocator)
protected TextBuffer(BufferRecycler allocator, char[] initialSegment)
public static TextBuffer fromInitial(char[] initialSegment)
initialSegment
- Initial, full segment to use for creating buffer (buffer
size()
would return length of initialSegment
)public void releaseBuffers()
Note: since Jackson 2.11, calling this method will NOT clear already
aggregated contents (that is, _currentSegment
, to retain
current token text if (but only if!) already aggregated.
public void resetWithEmpty()
public void resetWith(char ch)
size()
would return 1
)ch
- Character to set as the buffer contentspublic void resetWithShared(char[] buf, int offset, int len)
buf
- Buffer that contains shared contentsoffset
- Offset of the first content character in buf
len
- Length of content in buf
public void resetWithCopy(char[] buf, int offset, int len) throws IOException
buf
- Buffer that contains new contentsoffset
- Offset of the first content character in buf
len
- Length of content in buf
IOException
- if the buffer has grown too large, see StreamReadConstraints.Builder.maxStringLength(int)
public void resetWithCopy(String text, int start, int len) throws IOException
text
- String that contains new contentsstart
- Offset of the first content character in text
len
- Length of content in text
IOException
- if the buffer has grown too large, see StreamReadConstraints.Builder.maxStringLength(int)
public void resetWithString(String value) throws IOException
value
- to replace existing bufferIOException
- if the value is too large, see StreamReadConstraints.Builder.maxStringLength(int)
public char[] getBufferWithoutReset()
public BufferRecycler bufferRecycler()
public int size()
public int getTextOffset()
public boolean hasTextAsCharacters()
getTextBuffer()
.True
if access via getTextBuffer()
would be efficient
(that is, content already available as aggregated char[]
)public char[] getTextBuffer() throws IOException
char[]
regardless of whether they were collected in a segmented
fashion or not: this typically require allocation of the result buffer.char[]
that contains all buffered contentIOException
- if the text is too large, see StreamReadConstraints.Builder.maxStringLength(int)
public String contentsAsString() throws IOException
String
regardless of whether they were collected in a segmented
fashion or not: this typically require construction of the result String.String
IOException
- if the contents are too large, see StreamReadConstraints.Builder.maxStringLength(int)
public char[] contentsAsArray() throws IOException
IOException
- if the text is too large, see StreamReadConstraints.Builder.maxStringLength(int)
public double contentsAsDouble(boolean useFastParser) throws NumberFormatException
NOTE! Caller MUST validate contents before calling this method, to ensure textual version is valid JSON floating-point token -- this method is not guaranteed to do any validation and behavior with invalid content is not defined (either throws an exception or returns arbitrary number).
useFastParser
- whether to use FastDoubleParser
Double
, if possibleNumberFormatException
- may (but is not guaranteed!) be thrown
if contents are not a valid JSON floating-point number representation@Deprecated public double contentsAsDouble() throws NumberFormatException
contentsAsDouble(boolean)
Double
, if possibleNumberFormatException
- if contents are not a valid Java number@Deprecated public float contentsAsFloat() throws NumberFormatException
contentsAsFloat(boolean)
Float
, if possibleNumberFormatException
- if contents are not a valid Java numberpublic float contentsAsFloat(boolean useFastParser) throws NumberFormatException
NOTE! Caller MUST validate contents before calling this method, to ensure textual version is valid JSON floating-point token -- this method is not guaranteed to do any validation and behavior with invalid content is not defined (either throws an exception or returns arbitrary number).
useFastParser
- whether to use FastDoubleParser
Float
, if possibleNumberFormatException
- may (but is not guaranteed!) be thrown
if contents are not a valid JSON floating-point number representation@Deprecated public BigDecimal contentsAsDecimal() throws NumberFormatException
contentsAsDecimal(boolean)
instead.NumberFormatException
public BigDecimal contentsAsDecimal(boolean useFastParser) throws NumberFormatException
NumberFormatException
public int contentsAsInt(boolean neg)
NOTE: method DOES NOT verify that the contents actually are a valid
Java int
value (either regarding format, or value range): caller
MUST validate that.
neg
- Whether contents start with a minus signint
using
NumberInput.parseInt(String)
method (which does NOT validate input)public long contentsAsLong(boolean neg)
NOTE: method DOES NOT verify that the contents actually are a valid
Java long
value (either regarding format, or value range): caller
MUST validate that.
neg
- Whether contents start with a minus signlong
using
NumberInput.parseLong(String)
method (which does NOT validate input)public int contentsToWriter(Writer w) throws IOException
Writer
.w
- Writer to use for writing out buffered contentsize()
)IOException
- If write using Writer
parameter failspublic void ensureNotShared()
public void append(char c) throws IOException
c
- char to appendIOException
- if the buffer has grown too large, see StreamReadConstraints.Builder.maxStringLength(int)
public void append(char[] c, int start, int len) throws IOException
c
- char array to appendstart
- the start index within the array (from which we read chars to append)len
- number of chars to take from the arrayIOException
- if the buffer has grown too large, see StreamReadConstraints.Builder.maxStringLength(int)
public void append(String str, int offset, int len) throws IOException
str
- string to appendoffset
- the start index within the string (from which we read chars to append)len
- number of chars to take from the stringIOException
- if the buffer has grown too large, see StreamReadConstraints.Builder.maxStringLength(int)
public char[] getCurrentSegment()
public char[] emptyAndGetCurrentSegment()
public int getCurrentSegmentSize()
public void setCurrentLength(int len)
public String setCurrentAndReturn(int len) throws IOException
contentsAsString()
).len
- Length of content (in characters) of the current active segmentIOException
- if the text is too large, see StreamReadConstraints.Builder.maxStringLength(int)
public char[] finishCurrentSegment() throws IOException
IOException
- if the text is too large, see StreamReadConstraints.Builder.maxStringLength(int)
public String finishAndReturn(int lastSegmentEnd, boolean trimTrailingSpaces) throws IOException
lastSegmentEnd
- End offset in the currently active segment,
could be 0 in the case of first character is
delimiter or end-of-linetrimTrailingSpaces
- Whether trailing spaces should be trimmed or notIOException
- If length constraints (of longest allowed Text value) are violatedpublic char[] expandCurrentSegment()
public char[] expandCurrentSegment(int minSize)
minSize
- Required minimum strength of the current segmentpublic String toString()
contentsAsString()
, since it's not guaranteed that resulting
String is cached.protected void _reportBufferOverflow(int prev, int curr)
protected void validateStringLength(int length) throws IOException
JsonParseException
is thrown.length
- Length of string in input unitsIOException
- If length exceeds maximumCopyright © 2008–2024 FasterXML. All rights reserved.