Class 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) segment
      private boolean _hasSegments
      Flag that indicates whether _seqments is non-empty
      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.
      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 data
      private 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)  
    • Field Detail

      • NO_CHARS

        static final char[] NO_CHARS
      • _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
    • Constructor Detail

      • TextBuffer

        public TextBuffer​(com.fasterxml.jackson.core.util.BufferRecycler allocator)
    • 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 a BigDecimal.
        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-line
        trimTrailingSpaces - 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)