Top Description Fields Constructors Methods
com.fasterxml.jackson.core.io

public final Class NumberInput

extends Object
Class Inheritance
Imports
ch.randelshofer.fastdoubleparser.JavaDoubleParser, .JavaFloatParser, java.math.BigDecimal, .BigInteger

Helper class for efficient parsing of various JSON numbers.

Note

Does NOT validate against maximum length limits: caller must do that if and as necessary.

Field Summary

Modifier and TypeField and Description
pack-priv static final long
L_BILLION

Constants needed for parsing longs from basic int parsing methods

pack-priv static final String
pack-priv static final String
public static final String
NASTY_SMALL_DOUBLE

Formerly used constant for a value that was problematic on certain pre-1.8 JDKs.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

True if specified String representation is within Java long range; false if not.
inLongRange
(char[]
Buffer that contains long value to check
ch
,
int
Offset of the first digit character in buffer
off
,
int
Length of the number to decode (in characters)
len
,
boolean
Whether original number had a minus sign (which is NOT passed to this method) or not
negative
)

Helper method for determining if given String representation of an integral number would fit in 64-bit Java long or not.

public static boolean

Returns:

True if specified String representation is within Java long range; false if not.
inLongRange
(String
String that contains long value to check
s
,
boolean
Whether original number had a minus sign (which is NOT passed to this method) or not
negative
)

Similar to inLongRange(char[], int, int, boolean), but with String argument

public static double

Returns:

closest matching double (or `def` if there is an issue with `s`) where useFastParser=false
parseAsDouble
(final String
a string representing a number to parse
s
,
final double
the default to return if `s` is not a parseable number
def
)

public static double

Returns:

closest matching double (or `def` if there is an issue with `s`)
parseAsDouble
(String
a string representing a number to parse
s
,
final double
the default to return if `s` is not a parseable number
def
,
final boolean
whether to use FastDoubleParser
useFastParser
)

public static int
parseAsInt(String s, int def)

public static long
parseAsLong(String s, long def)

public static BigDecimal

Returns:

a BigDecimal
parseBigDecimal
(final String
a string representing a number to parse
s
)

public static BigDecimal

Returns:

a BigDecimal
parseBigDecimal
(final String
a string representing a number to parse
s
,
final boolean
whether to use custom fast parser (true) or JDK default (false) parser
useFastParser
)

public static BigDecimal

Returns:

a BigDecimal
parseBigDecimal
(final char[]
a char array with text that makes up a number
ch
,
final int
the offset to apply when parsing the number in the char array
off
,
final int
the length of the number in the char array
len
)

public static BigDecimal

Returns:

a BigDecimal
parseBigDecimal
(final char[]
a char array with text that makes up a number
ch
,
final int
the offset to apply when parsing the number in the char array
off
,
final int
the length of the number in the char array
len
,
final boolean
whether to use custom fast parser (true) or JDK default (false) parser
useFastParser
)

public static BigDecimal

Returns:

a BigDecimal
parseBigDecimal
(final char[]
a char array with text that makes up a number
ch
)

public static BigDecimal

Returns:

a BigDecimal
parseBigDecimal
(final char[]
a char array with text that makes up a number
ch
,
final boolean
whether to use custom fast parser (true) or JDK default (false) parser
useFastParser
)

public static BigInteger

Returns:

a BigInteger
parseBigInteger
(final String
a string representing a number to parse
s
)

public static BigInteger

Returns:

a BigInteger
parseBigInteger
(final String
a string representing a number to parse
s
,
final boolean
whether to use custom fast parser (true) or JDK default (false) parser
useFastParser
)

public static BigInteger

Returns:

a BigInteger
parseBigIntegerWithRadix
(final String
a string representing a number to parse
s
,
final int
for parse
radix
,
final boolean
whether to use custom fast parser (true) or JDK default (false) parser
useFastParser
)

public static double

Returns:

closest matching double
parseDouble
(final String
a string representing a number to parse
s
)

public static double

Returns:

closest matching double
parseDouble
(final String
a string representing a number to parse
s
,
final boolean
whether to use FastDoubleParser
useFastParser
)

public static float

Returns:

closest matching float
parseFloat
(final String
a string representing a number to parse
s
)

public static float

Returns:

closest matching float
parseFloat
(final String
a string representing a number to parse
s
,
final boolean
whether to use FastDoubleParser
useFastParser
)

public static int

Returns:

Decoded int value
parseInt
(char[]
Buffer that contains integer value to decode
ch
,
int
Offset of the first digit character in buffer
off
,
int
Length of the number to decode (in characters)
len
)

Fast method for parsing unsigned integers that are known to fit into regular 32-bit signed int type.

public static int

Returns:

Decoded int value
parseInt
(String
String that contains integer value to decode
s
)

Helper method to (more) efficiently parse integer numbers from String values.

public static long
parseLong(char[] ch, int off, int len)

public static long

Returns:

Decoded long value
parseLong
(String
String that contains long value to decode
s
)

Similar to parseInt(String) but for long values.

public static long

Returns:

Decoded long value
parseLong19
(char[]
Buffer that contains integer value to decode
ch
,
int
Offset of the first digit character in buffer
off
,
boolean
Whether original number had a minus sign
negative
)

Parses an unsigned long made up of exactly 19 digits.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

L_BILLIONback to summary
pack-priv static final long L_BILLION

Constants needed for parsing longs from basic int parsing methods

MAX_LONG_STRback to summary
pack-priv static final String MAX_LONG_STR
MIN_LONG_STR_NO_SIGNback to summary
pack-priv static final String MIN_LONG_STR_NO_SIGN
NASTY_SMALL_DOUBLEback to summary
public static final String NASTY_SMALL_DOUBLE

Deprecated

Since 2.14 -- do not use

Formerly used constant for a value that was problematic on certain pre-1.8 JDKs.

Annotations
@Deprecated

Constructor Detail

NumberInputback to summary
public NumberInput()

Method Detail

inLongRangeback to summary
public static boolean inLongRange(char[] ch, int off, int len, boolean negative)

Helper method for determining if given String representation of an integral number would fit in 64-bit Java long or not. Note that input String must NOT contain leading minus sign (even if 'negative' is set to true).

Parameters
ch:char[]

Buffer that contains long value to check

off:int

Offset of the first digit character in buffer

len:int

Length of the number to decode (in characters)

negative:boolean

Whether original number had a minus sign (which is NOT passed to this method) or not

Returns:boolean

True if specified String representation is within Java long range; false if not.

inLongRangeback to summary
public static boolean inLongRange(String s, boolean negative)

Similar to inLongRange(char[], int, int, boolean), but with String argument

Parameters
s:String

String that contains long value to check

negative:boolean

Whether original number had a minus sign (which is NOT passed to this method) or not

Returns:boolean

True if specified String representation is within Java long range; false if not.

parseAsDoubleback to summary
public static double parseAsDouble(final String s, final double def)
Parameters
s:String

a string representing a number to parse

def:double

the default to return if `s` is not a parseable number

Returns:double

closest matching double (or `def` if there is an issue with `s`) where useFastParser=false

See Also
parseAsDouble(String, double, boolean)
parseAsDoubleback to summary
public static double parseAsDouble(String s, final double def, final boolean useFastParser)
Parameters
s:String

a string representing a number to parse

def:double

the default to return if `s` is not a parseable number

useFastParser:boolean

whether to use FastDoubleParser

Returns:double

closest matching double (or `def` if there is an issue with `s`)

Since
2.14
parseAsIntback to summary
public static int parseAsInt(String s, int def)
parseAsLongback to summary
public static long parseAsLong(String s, long def)
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(final String s) throws NumberFormatException
Parameters
s:String

a string representing a number to parse

Returns:BigDecimal

a BigDecimal

Exceptions
NumberFormatException:
if the char array cannot be represented by a BigDecimal
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(final String s, final boolean useFastParser) throws NumberFormatException
Parameters
s:String

a string representing a number to parse

useFastParser:boolean

whether to use custom fast parser (true) or JDK default (false) parser

Returns:BigDecimal

a BigDecimal

Exceptions
NumberFormatException:
if the char array cannot be represented by a BigDecimal
Since
v2.15
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(final char[] ch, final int off, final int len) throws NumberFormatException
Parameters
ch:char[]

a char array with text that makes up a number

off:int

the offset to apply when parsing the number in the char array

len:int

the length of the number in the char array

Returns:BigDecimal

a BigDecimal

Exceptions
NumberFormatException:
if the char array cannot be represented by a BigDecimal
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(final char[] ch, final int off, final int len, final boolean useFastParser) throws NumberFormatException
Parameters
ch:char[]

a char array with text that makes up a number

off:int

the offset to apply when parsing the number in the char array

len:int

the length of the number in the char array

useFastParser:boolean

whether to use custom fast parser (true) or JDK default (false) parser

Returns:BigDecimal

a BigDecimal

Exceptions
NumberFormatException:
if the char array cannot be represented by a BigDecimal
Since
v2.15
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(final char[] ch) throws NumberFormatException
Parameters
ch:char[]

a char array with text that makes up a number

Returns:BigDecimal

a BigDecimal

Exceptions
NumberFormatException:
if the char array cannot be represented by a BigDecimal
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(final char[] ch, final boolean useFastParser) throws NumberFormatException
Parameters
ch:char[]

a char array with text that makes up a number

useFastParser:boolean

whether to use custom fast parser (true) or JDK default (false) parser

Returns:BigDecimal

a BigDecimal

Exceptions
NumberFormatException:
if the char array cannot be represented by a BigDecimal
Since
v2.15
parseBigIntegerback to summary
public static BigInteger parseBigInteger(final String s) throws NumberFormatException
Parameters
s:String

a string representing a number to parse

Returns:BigInteger

a BigInteger

Exceptions
NumberFormatException:
if string cannot be represented by a BigInteger
Since
v2.14
parseBigIntegerback to summary
public static BigInteger parseBigInteger(final String s, final boolean useFastParser) throws NumberFormatException
Parameters
s:String

a string representing a number to parse

useFastParser:boolean

whether to use custom fast parser (true) or JDK default (false) parser

Returns:BigInteger

a BigInteger

Exceptions
NumberFormatException:
if string cannot be represented by a BigInteger
Since
v2.15
parseBigIntegerWithRadixback to summary
public static BigInteger parseBigIntegerWithRadix(final String s, final int radix, final boolean useFastParser) throws NumberFormatException
Parameters
s:String

a string representing a number to parse

radix:int

for parse

useFastParser:boolean

whether to use custom fast parser (true) or JDK default (false) parser

Returns:BigInteger

a BigInteger

Exceptions
NumberFormatException:
if string cannot be represented by a BigInteger
Since
v2.15
parseDoubleback to summary
public static double parseDouble(final String s) throws NumberFormatException
Parameters
s:String

a string representing a number to parse

Returns:double

closest matching double

Exceptions
NumberFormatException:
if string cannot be represented by a double where useFastParser=false
See Also
parseDouble(String, boolean)
parseDoubleback to summary
public static double parseDouble(final String s, final boolean useFastParser) throws NumberFormatException
Parameters
s:String

a string representing a number to parse

useFastParser:boolean

whether to use FastDoubleParser

Returns:double

closest matching double

Exceptions
NumberFormatException:
if string cannot be represented by a double
Since
v2.14
parseFloatback to summary
public static float parseFloat(final String s) throws NumberFormatException
Parameters
s:String

a string representing a number to parse

Returns:float

closest matching float

Exceptions
NumberFormatException:
if string cannot be represented by a float where useFastParser=false
Since
v2.14
See Also
parseFloat(String, boolean)
parseFloatback to summary
public static float parseFloat(final String s, final boolean useFastParser) throws NumberFormatException
Parameters
s:String

a string representing a number to parse

useFastParser:boolean

whether to use FastDoubleParser

Returns:float

closest matching float

Exceptions
NumberFormatException:
if string cannot be represented by a float
Since
v2.14
parseIntback to summary
public static int parseInt(char[] ch, int off, int len)

Fast method for parsing unsigned integers that are known to fit into regular 32-bit signed int type. This means that length is between 1 and 9 digits (inclusive) and there is no sign character.

Note

public to let unit tests call it; not meant to be used by any code outside this package.

Parameters
ch:char[]

Buffer that contains integer value to decode

off:int

Offset of the first digit character in buffer

len:int

Length of the number to decode (in characters)

Returns:int

Decoded int value

parseIntback to summary
public static int parseInt(String s)

Helper method to (more) efficiently parse integer numbers from String values. Input String must be simple Java integer value. No range checks are made to verify that the value fits in 32-bit Java int: caller is expected to only calls this in cases where this can be guaranteed (basically: number of digits does not exceed 9)

Note

semantics differ significantly from parseInt(char[], int, int).

Parameters
s:String

String that contains integer value to decode

Returns:int

Decoded int value

parseLongback to summary
public static long parseLong(char[] ch, int off, int len)
parseLongback to summary
public static long parseLong(String s)

Similar to parseInt(String) but for long values.

Parameters
s:String

String that contains long value to decode

Returns:long

Decoded long value

parseLong19back to summary
public static long parseLong19(char[] ch, int off, boolean negative)

Parses an unsigned long made up of exactly 19 digits.

It is the callers responsibility to make sure the input is exactly 19 digits. and fits into a 64bit long by calling inLongRange(char[], int, int, boolean) first.

Note that input String must NOT contain leading minus sign (even if negative is set to true).

Parameters
ch:char[]

Buffer that contains integer value to decode

off:int

Offset of the first digit character in buffer

negative:boolean

Whether original number had a minus sign

Returns:long

Decoded long value

Since
2.15.0