Class TextBuffer

java.lang.Object
com.fasterxml.jackson.dataformat.csv.impl.TextBuffer

public final class TextBuffer extends Object
Helper class for efficiently aggregating parsed and decoded textual content
  • Field Details

    • NO_CHARS

      static final char[] NO_CHARS
    • MIN_SEGMENT_LEN

      static final int MIN_SEGMENT_LEN
      See Also:
    • MAX_SEGMENT_LEN

      static final int MAX_SEGMENT_LEN
      See Also:
    • _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 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 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
  • Constructor Details

    • TextBuffer

      public TextBuffer(com.fasterxml.jackson.core.util.BufferRecycler allocator)
  • Method Details

    • releaseBuffers

      public void releaseBuffers()
    • reset

      public void reset()
    • resetWithString

      public void resetWithString(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 String contentsAsString()
    • contentsAsArray

      public char[] contentsAsArray()
    • contentsAsDecimal

      public BigDecimal contentsAsDecimal() throws NumberFormatException
      Convenience method for converting contents of the buffer into a BigDecimal.
      Throws:
      NumberFormatException
    • contentsAsDouble

      public double contentsAsDouble() throws NumberFormatException
      Convenience method for converting contents of the buffer into a Double value.
      Throws:
      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 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-line
      trimTrailingSpaces - Whether trailing spaces should be trimmed or not
    • _doTrim

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