Class ParserBase

All Implemented Interfaces:
Closeable, AutoCloseable, Versioned
Direct Known Subclasses:
JsonParserBase

public abstract class ParserBase extends ParserMinimalBase
Intermediate base class used by many (but not all) Jackson JsonParser implementations. Contains most common things that are independent of actual underlying input source.
  • Field Details

    • _inputPtr

      protected int _inputPtr
      Pointer to next available character in buffer
    • _inputEnd

      protected int _inputEnd
      Index of character after last available one in the buffer.
    • _currInputProcessed

      protected long _currInputProcessed
      Number of characters/bytes that were contained in previous blocks (blocks that were already processed prior to the current buffer).
    • _currInputRow

      protected int _currInputRow
      Current row location of current point in input buffer, starting from 1, if available.
    • _currInputRowStart

      protected int _currInputRowStart
      Current index of the first character of the current row in input buffer. Needed to calculate column position, if necessary; benefit of not having column itself is that this only has to be updated once per line.
    • _tokenInputTotal

      protected long _tokenInputTotal
      Total number of bytes/characters read before start of current token. For big (gigabyte-sized) sizes are possible, needs to be long, unlike pointers and sizes related to in-memory buffers.
    • _tokenInputRow

      protected int _tokenInputRow
      Input row on which current token starts, 1-based
    • _tokenInputCol

      protected int _tokenInputCol
      Column on input row that current token starts; 0-based (although in the end it'll be converted to 1-based)
    • _textBuffer

      protected final TextBuffer _textBuffer
      Buffer that contains contents of String values, including property names if necessary (name split across boundary, contains escape sequence, or access needed to char array)
    • _byteArrayBuilder

      protected ByteArrayBuilder _byteArrayBuilder
      ByteArrayBuilder is needed if 'getBinaryValue' is called. If so, we better reuse it for remainder of content.
    • _binaryValue

      protected byte[] _binaryValue
      We will hold on to decoded binary data, for duration of current event, so that multiple calls to getBinaryValue(tools.jackson.core.Base64Variant) will not need to decode data more than once.
    • _numTypesValid

      protected int _numTypesValid
      Bitfield that indicates which numeric representations have been calculated for the current type
    • _numberInt

      protected int _numberInt
    • _numberLong

      protected long _numberLong
    • _numberFloat

      protected float _numberFloat
    • _numberDouble

      protected double _numberDouble
    • _numberBigInt

      protected BigInteger _numberBigInt
    • _numberBigDecimal

      protected BigDecimal _numberBigDecimal
    • _numberString

      protected String _numberString
      Textual number representation captured from input in cases lazy-parsing is desired.
    • _numberIsNaN

      protected boolean _numberIsNaN
      Marker for explicit "Not a Number" (NaN) values that may be read by some formats: this includes positive and negative infinity, as well as "NaN" result for some arithmetic operations.

      In case of JSON, such values can only be handled with non-standard processing: for some other formats they can be passed normally.

      NOTE: this marker is NOT set in case of value overflow/underflow for double or float values.

      Since:
      2.17
    • _numberNegative

      protected boolean _numberNegative
      Flag that indicates whether numeric value has a negative value. That is, whether its textual representation starts with minus character.
    • _intLength

      protected int _intLength
      Length of integer part of the number, in characters
    • _fractLength

      protected int _fractLength
      Length of the fractional part (not including decimal point or exponent), in characters. Not used for pure integer values.
    • _expLength

      protected int _expLength
      Length of the exponent part of the number, if any, not including 'e' marker or sign, just digits. Not used for pure integer values.
  • Constructor Details

  • Method Details

    • assignCurrentValue

      public void assignCurrentValue(Object v)
      Description copied from class: JsonParser
      Helper method, usually equivalent to: getParsingContext().assignCurrentValue(v);
      Specified by:
      assignCurrentValue in class JsonParser
      Parameters:
      v - "Current value" to assign to the current input context of this parser
    • currentValue

      public Object currentValue()
      Description copied from class: JsonParser
      Helper method, usually equivalent to: getParsingContext().currentValue();

      Note that "current value" is NOT populated (or used) by Streaming parser; it is only used by higher-level data-binding functionality. The reason it is included here is that it can be stored and accessed hierarchically, and gets passed through data-binding.

      Specified by:
      currentValue in class JsonParser
      Returns:
      "Current value" for the current input context this parser has
    • close

      public void close() throws JacksonException
      Method that can be called to get the name associated with the current event.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class ParserMinimalBase
      Throws:
      JacksonException
    • hasStringCharacters

      public boolean hasStringCharacters()
      Description copied from class: JsonParser
      Method that can be used to determine whether calling of JsonParser.getStringCharacters() would be the most efficient way to access String value for the event parser currently points to (compared to JsonParser.getString()).
      Specified by:
      hasStringCharacters in class JsonParser
      Returns:
      True if parser currently has character array that can be efficiently returned via JsonParser.getStringCharacters(); false means that it may or may not exist
    • getBinaryValue

      public byte[] getBinaryValue(Base64Variant variant) throws JacksonException
      Description copied from class: JsonParser
      Method that can be used to read (and consume -- results may not be accessible using other methods after the call) base64-encoded binary data included in the current textual JSON value. It works similar to getting String value via JsonParser.getString() and decoding result (except for decoding part), but should be significantly more performant.

      Note that non-decoded textual contents of the current token are not guaranteed to be accessible after this method is called. Current implementation, for example, clears up textual content during decoding. Decoded binary content, however, will be retained until parser is advanced to the next event.

      Specified by:
      getBinaryValue in class JsonParser
      Parameters:
      variant - Expected variant of base64 encoded content (see Base64Variants for definitions of "standard" variants).
      Returns:
      Decoded binary data
      Throws:
      JacksonIOException - for low-level read issues
      StreamReadException - for decoding problems
      JacksonException
    • getTokenCharacterOffset

      public long getTokenCharacterOffset()
    • getTokenLineNr

      public int getTokenLineNr()
    • getTokenColumnNr

      public int getTokenColumnNr()
    • _releaseBuffers

      protected void _releaseBuffers()
      Description copied from class: ParserMinimalBase
      Method called to release internal buffers owned by the base reader. This is expected to be called after ParserMinimalBase._closeInput() since the buffers are expected not to be needed any longer.
      Specified by:
      _releaseBuffers in class ParserMinimalBase
    • _handleEOF

      protected void _handleEOF() throws JacksonException
      Method called when an EOF is encountered between tokens. If so, it may be a legitimate EOF, but only if there is no open non-root context.
      Specified by:
      _handleEOF in class ParserMinimalBase
      Throws:
      JacksonException - if end-of-content not allowed at current position.
    • _eofAsNextChar

      protected final int _eofAsNextChar() throws StreamReadException
      Returns:
      If no exception is thrown, -1 which is used as marked for "end-of-input"
      Throws:
      StreamReadException - If check on _handleEOF() fails; usually because the current context is not root context (missing end markers in content)
    • _getByteArrayBuilder

      protected ByteArrayBuilder _getByteArrayBuilder()
    • reset

      protected final JsonToken reset(boolean negative, int intLen, int fractLen, int expLen) throws JacksonException
      Throws:
      JacksonException
    • resetInt

      protected final JsonToken resetInt(boolean negative, int intLen) throws JacksonException
      Throws:
      JacksonException
    • resetFloat

      protected final JsonToken resetFloat(boolean negative, int intLen, int fractLen, int expLen) throws JacksonException
      Throws:
      JacksonException
    • resetAsNaN

      protected final JsonToken resetAsNaN(String valueStr, double value)
    • isNaN

      public boolean isNaN()
      Description copied from class: JsonParser
      Accessor for checking whether current token is a special "not-a-number" (NaN) token (including both "NaN" AND positive/negative infinity!). These values are not supported by all formats: JSON, for example, only supports them if JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS is enabled.

      NOTE: in case where numeric value is outside range of requested type -- most notably Float or Double -- and decoding results effectively in a NaN value, this method DOES NOT return true: only explicit incoming markers do. This is because value could still be accessed as a valid BigDecimal.

      Specified by:
      isNaN in class JsonParser
      Returns:
      True if the current token is reported as JsonToken.VALUE_NUMBER_FLOAT and represents a "Not a Number" value; false for other tokens and regular floating-point numbers.
    • getNumberValue

      public Number getNumberValue()
      Description copied from class: JsonParser
      Generic number value accessor method that will work for all kinds of numeric values. It will return the optimal (simplest/smallest possible) wrapper object that can express the numeric value just parsed.
      Specified by:
      getNumberValue in class JsonParser
      Returns:
      Numeric value of the current token in its most optimal representation
    • getNumberValueExact

      public Number getNumberValueExact()
      Description copied from class: JsonParser
      Method similar to JsonParser.getNumberValue() with the difference that for floating-point numbers value returned may be BigDecimal if the underlying format does not store floating-point numbers using native representation: for example, textual formats represent numbers as Strings (which are 10-based), and conversion to Double is potentially lossy operation.

      Default implementation simply returns JsonParser.getNumberValue()

      Overrides:
      getNumberValueExact in class ParserMinimalBase
      Returns:
      Numeric value of the current token using most accurate representation
    • getNumberValueDeferred

      public Object getNumberValueDeferred()
      Description copied from class: JsonParser
      Method similar to JsonParser.getNumberValue() but that returns either same Number value as JsonParser.getNumberValue() (if already decoded), or String representation of as-of-yet undecoded number. Typically textual formats allow deferred decoding from String, whereas binary formats either decode numbers eagerly or have binary representation from which to decode value to return.

      Same constraints apply to calling this method as to JsonParser.getNumberValue(): current token must be either JsonToken.VALUE_NUMBER_INT or JsonToken.VALUE_NUMBER_FLOAT; otherwise an exception is thrown

      Default implementation simply returns JsonParser.getNumberValue()

      Overrides:
      getNumberValueDeferred in class ParserMinimalBase
      Returns:
      Either Number (for already decoded numbers) or String (for deferred decoding).
    • getNumberType

      public JsonParser.NumberType getNumberType()
      Description copied from class: JsonParser
      If current token is of type JsonToken.VALUE_NUMBER_INT or JsonToken.VALUE_NUMBER_FLOAT, returns one of JsonParser.NumberType constants; otherwise returns null.

      NOTE: in Jackson 2.x, an exception was wrong if called for non-numeric token.

      Specified by:
      getNumberType in class JsonParser
      Returns:
      Type of current number, if parser points to numeric token; null otherwise
    • getIntValue

      public int getIntValue() throws JacksonException
      Description copied from class: JsonParser
      Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a value of Java int primitive type. It can also be called for JsonToken.VALUE_NUMBER_FLOAT; if so, it is equivalent to calling JsonParser.getDoubleValue() and then casting; except for possible overflow/underflow exception.

      Note: if the resulting integer value falls outside range of Java int, a InputCoercionException may be thrown to indicate numeric overflow/underflow.

      Specified by:
      getIntValue in class JsonParser
      Returns:
      Current number value as int (if numeric token within Java 32-bit signed int range); otherwise exception thrown
      Throws:
      InputCoercionException - If either token type is not a number OR numeric value exceeds allowed range
      JacksonException
    • getLongValue

      public long getLongValue() throws JacksonException
      Description copied from class: JsonParser
      Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it can be expressed as a Java long primitive type. It can also be called for JsonToken.VALUE_NUMBER_FLOAT; if so, it is equivalent to calling JsonParser.getDoubleValue() and then casting to int; except for possible overflow/underflow exception.

      Note: if the token is an integer, but its value falls outside of range of Java long, a InputCoercionException may be thrown to indicate numeric overflow/underflow.

      Specified by:
      getLongValue in class JsonParser
      Returns:
      Current number value as long (if numeric token within Java 32-bit signed long range); otherwise exception thrown
      Throws:
      InputCoercionException - If either token type is not a number OR numeric value exceeds allowed range
      JacksonException
    • getBigIntegerValue

      public BigInteger getBigIntegerValue() throws JacksonException
      Description copied from class: JsonParser
      Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_INT and it cannot be used as a Java long primitive type due to its magnitude. It can also be called for JsonToken.VALUE_NUMBER_FLOAT; if so, it is equivalent to calling JsonParser.getDecimalValue() and then constructing a BigInteger from that value.
      Specified by:
      getBigIntegerValue in class JsonParser
      Returns:
      Current number value as BigInteger (if numeric token); otherwise exception thrown
      Throws:
      InputCoercionException - If either token type is not a number
      JacksonException
    • getFloatValue

      public float getFloatValue() throws JacksonException
      Description copied from class: JsonParser
      Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT and it can be expressed as a Java float primitive type. It can also be called for JsonToken.VALUE_NUMBER_INT; if so, it is equivalent to calling JsonParser.getLongValue() and then casting; except for possible overflow/underflow exception.

      Note: if the value falls outside of range of Java float, a InputCoercionException will be thrown to indicate numeric overflow/underflow.

      Specified by:
      getFloatValue in class JsonParser
      Returns:
      Current number value as float (if numeric token within Java float range); otherwise exception thrown
      Throws:
      InputCoercionException - If either token type is not a number OR numeric value exceeds allowed range
      JacksonException
    • getDoubleValue

      public double getDoubleValue() throws JacksonException
      Description copied from class: JsonParser
      Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT and it can be expressed as a Java double primitive type. It can also be called for JsonToken.VALUE_NUMBER_INT; if so, it is equivalent to calling JsonParser.getLongValue() and then casting; except for possible overflow/underflow exception.

      Note: if the value falls outside of range of Java double, a InputCoercionException will be thrown to indicate numeric overflow/underflow.

      Specified by:
      getDoubleValue in class JsonParser
      Returns:
      Current number value as double (if numeric token within Java double range); otherwise exception thrown
      Throws:
      InputCoercionException - If either token type is not a number OR numeric value exceeds allowed range
      JacksonException
    • getDecimalValue

      public BigDecimal getDecimalValue() throws JacksonException
      Description copied from class: JsonParser
      Numeric accessor that can be called when the current token is of type JsonToken.VALUE_NUMBER_FLOAT or JsonToken.VALUE_NUMBER_INT. No under/overflow exceptions are ever thrown.
      Specified by:
      getDecimalValue in class JsonParser
      Returns:
      Current number value as BigDecimal (if numeric token); otherwise exception thrown
      Throws:
      InputCoercionException - If either token type is not a number
      JacksonException
    • _parseNumericValue

      protected abstract void _parseNumericValue(int expType) throws JacksonException, InputCoercionException
      Method that will parse actual numeric value out of a syntactically valid number value. Type it will parse into depends on whether it is a floating point number, as well as its magnitude: smallest legal type (of ones available) is used for efficiency.
      Parameters:
      expType - Numeric type that we will immediately need, if any; mostly necessary to optimize handling of floating point numbers
      Throws:
      JacksonIOException - for low-level read issues
      InputCoercionException - if the current token not of numeric type
      StreamReadException - for number decoding problems
      JacksonException
    • _parseIntValue

      protected abstract int _parseIntValue() throws JacksonException
      Throws:
      JacksonException
    • convertNumberToInt

      protected void convertNumberToInt() throws InputCoercionException
      Throws:
      InputCoercionException
    • convertNumberToLong

      protected void convertNumberToLong() throws InputCoercionException
      Throws:
      InputCoercionException
    • convertNumberToBigInteger

      protected void convertNumberToBigInteger()
    • convertNumberToDouble

      protected void convertNumberToDouble()
    • convertNumberToFloat

      protected void convertNumberToFloat()
    • convertNumberToBigDecimal

      protected void convertNumberToBigDecimal()
    • _convertBigDecimalToBigInteger

      protected BigInteger _convertBigDecimalToBigInteger(BigDecimal bigDec)
    • _getBigInteger

      protected BigInteger _getBigInteger()
      Internal accessor that needs to be used for accessing number value of type BigInteger which -- as of 2.14 -- is typically lazily parsed.
      Returns:
      BigInteger value decoded or converted for the current event
    • _getBigDecimal

      protected BigDecimal _getBigDecimal()
      Internal accessor that needs to be used for accessing number value of type BigDecimal which -- as of 2.14 -- is typically lazily parsed.
      Returns:
      BigDecimal value decoded or converted for the current event
    • _getNumberDouble

      protected double _getNumberDouble()
      Internal accessor that needs to be used for accessing number value of type double which will be lazily parsed.
      Returns:
      double value decoded or converted for the current event
    • _getNumberFloat

      protected float _getNumberFloat()
      Internal accessor that needs to be used for accessing number value of type float which will be lazily parsed.
      Returns:
      float value decoded or converted for the current event
      Since:
      2.15
    • _decodeEscaped

      protected char _decodeEscaped() throws JacksonException
      Method that sub-classes must implement to support escaped sequences in base64-encoded sections. Sub-classes that do not need base64 support can leave this as is
      Returns:
      Character decoded, if any
      Throws:
      JacksonException - If escape decoding fails
    • _decodeBase64Escape

      protected final int _decodeBase64Escape(Base64Variant b64variant, int ch, int index) throws JacksonException
      Throws:
      JacksonException
    • _decodeBase64Escape

      protected final int _decodeBase64Escape(Base64Variant b64variant, char ch, int index) throws JacksonException
      Throws:
      JacksonException
    • _reportInvalidBase64Char

      protected <T> T _reportInvalidBase64Char(Base64Variant b64variant, int ch, int bindex) throws StreamReadException
      Throws:
      StreamReadException
    • _reportInvalidBase64Char

      protected <T> T _reportInvalidBase64Char(Base64Variant b64variant, int ch, int bindex, String msg) throws StreamReadException
      Throws:
      StreamReadException
    • _handleBase64MissingPadding

      protected <T> T _handleBase64MissingPadding(Base64Variant b64variant) throws StreamReadException
      Throws:
      StreamReadException
    • _contentReference

      protected ContentReference _contentReference()
      Helper method used to encapsulate logic of including (or not) of "content reference" when constructing TokenStreamLocation instances.
      Returns:
      ContentReference object to use.
    • _contentReferenceRedacted

      protected ContentReference _contentReferenceRedacted()
      Helper method used to encapsulate logic of providing "content reference" when constructing TokenStreamLocation instances and source information is NOT to be included (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled).

      Default implementation will simply return ContentReference.redacted().

      Returns:
      ContentReference object to use when source is not to be included
    • growArrayBy

      protected static int[] growArrayBy(int[] arr, int more) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • _growNameDecodeBuffer

      protected int[] _growNameDecodeBuffer(int[] arr, int more) throws StreamConstraintsException
      Throws:
      StreamConstraintsException