Class TextBuffer
- java.lang.Object
-
- com.fasterxml.jackson.dataformat.csv.impl.TextBuffer
-
public final class TextBuffer extends java.lang.Object
Helper class for efficiently aggregating parsed and decoded textual content
-
-
Field Summary
Fields Modifier and Type Field Description private com.fasterxml.jackson.core.util.BufferRecycler
_allocator
private char[]
_currentSegment
private int
_currentSize
Number of characters in currently active (last) segmentprivate boolean
_hasSegments
Flag that indicates whether _seqments is non-emptyprivate char[]
_inputBuffer
Shared input buffer; stored here in case some input can be returned as is, without being copied to collector's own buffers.private int
_inputLen
private int
_inputStart
Character offset of first char in input buffer; -1 to indicate that input buffer currently does not contain any useful char dataprivate char[]
_resultArray
private java.lang.String
_resultString
String that will be constructed when the whole contents are needed; will be temporarily stored in case asked for again.private java.util.LinkedList<char[]>
_segments
List of segments prior to currently active segment.private int
_segmentSize
Amount of characters in segments in_segments
(package private) static int
MAX_SEGMENT_LEN
(package private) static int
MIN_SEGMENT_LEN
(package private) static char[]
NO_CHARS
-
Constructor Summary
Constructors Constructor Description TextBuffer(com.fasterxml.jackson.core.util.BufferRecycler allocator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private char[]
_charArray(int len)
private java.lang.String
_doTrim(int ptr)
private char[]
buildResultArray()
private void
clearSegments()
char[]
contentsAsArray()
java.math.BigDecimal
contentsAsDecimal()
Convenience method for converting contents of the buffer into aBigDecimal
.double
contentsAsDouble()
Convenience method for converting contents of the buffer into a Double value.java.lang.String
contentsAsString()
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.private void
expand(int minNewSegmentSize)
private char[]
findBuffer(int needed)
Helper method used to find a buffer to use, ideally one recycled earlier.java.lang.String
finishAndReturn(int lastSegmentEnd, boolean trimTrailingSpaces)
char[]
finishCurrentSegment()
char[]
getCurrentSegment()
int
getCurrentSegmentSize()
char[]
getTextBuffer()
int
getTextOffset()
boolean
hasTextAsCharacters()
boolean
looksLikeInt()
void
releaseBuffers()
void
reset()
void
resetWithString(java.lang.String value)
int
size()
private void
unshare(int needExtra)
Method called if/when we need to append content when we have been initialized to use shared buffer.
-
-
-
Field Detail
-
NO_CHARS
static final char[] NO_CHARS
-
MIN_SEGMENT_LEN
static final int MIN_SEGMENT_LEN
- See Also:
- Constant Field Values
-
MAX_SEGMENT_LEN
static final int MAX_SEGMENT_LEN
- See Also:
- Constant Field Values
-
_allocator
private final com.fasterxml.jackson.core.util.BufferRecycler _allocator
-
_inputBuffer
private char[] _inputBuffer
Shared input buffer; stored here in case some input can be returned as is, without being copied to collector's own buffers.
-
_inputStart
private int _inputStart
Character offset of first char in input buffer; -1 to indicate that input buffer currently does not contain any useful char data
-
_inputLen
private int _inputLen
-
_segments
private java.util.LinkedList<char[]> _segments
List of segments prior to currently active segment.
-
_hasSegments
private boolean _hasSegments
Flag that indicates whether _seqments is non-empty
-
_segmentSize
private int _segmentSize
Amount of characters in segments in_segments
-
_currentSegment
private char[] _currentSegment
-
_currentSize
private int _currentSize
Number of characters in currently active (last) segment
-
_resultString
private java.lang.String _resultString
String that will be constructed when the whole contents are needed; will be temporarily stored in case asked for again.
-
_resultArray
private char[] _resultArray
-
-
Method Detail
-
releaseBuffers
public void releaseBuffers()
-
reset
public void reset()
-
resetWithString
public void resetWithString(java.lang.String value)
-
findBuffer
private final char[] findBuffer(int needed)
Helper method used to find a buffer to use, ideally one recycled earlier.
-
clearSegments
private final void clearSegments()
-
size
public int size()
- Returns:
- Number of characters currently stored by this collector
-
getTextOffset
public int getTextOffset()
-
hasTextAsCharacters
public boolean hasTextAsCharacters()
-
getTextBuffer
public char[] getTextBuffer()
-
contentsAsString
public java.lang.String contentsAsString()
-
contentsAsArray
public char[] contentsAsArray()
-
contentsAsDecimal
public java.math.BigDecimal contentsAsDecimal() throws java.lang.NumberFormatException
Convenience method for converting contents of the buffer into aBigDecimal
.- Throws:
java.lang.NumberFormatException
-
contentsAsDouble
public double contentsAsDouble() throws java.lang.NumberFormatException
Convenience method for converting contents of the buffer into a Double value.- Throws:
java.lang.NumberFormatException
-
looksLikeInt
public boolean looksLikeInt()
-
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.
-
getCurrentSegment
public char[] getCurrentSegment()
-
emptyAndGetCurrentSegment
public final char[] emptyAndGetCurrentSegment()
-
getCurrentSegmentSize
public int getCurrentSegmentSize()
-
finishAndReturn
public java.lang.String finishAndReturn(int lastSegmentEnd, boolean trimTrailingSpaces)
- Parameters:
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 not
-
_doTrim
private java.lang.String _doTrim(int ptr)
-
finishCurrentSegment
public char[] finishCurrentSegment()
-
unshare
private void unshare(int needExtra)
Method called if/when we need to append content when we have been initialized to use shared buffer.
-
expand
private void expand(int minNewSegmentSize)
-
buildResultArray
private char[] buildResultArray()
-
_charArray
private final char[] _charArray(int len)
-
-