本文整理汇总了Java中com.fasterxml.jackson.core.io.NumberInput类的典型用法代码示例。如果您正苦于以下问题:Java NumberInput类的具体用法?Java NumberInput怎么用?Java NumberInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NumberInput类属于com.fasterxml.jackson.core.io包,在下文中一共展示了NumberInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _parseSlowInt
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
private void _parseSlowInt(int expType) throws IOException
{
String numStr = _textBuffer.contentsAsString();
try {
int len = _intLength;
char[] buf = _textBuffer.getTextBuffer();
int offset = _textBuffer.getTextOffset();
if (_numberNegative) {
++offset;
}
// Some long cases still...
if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) {
// Probably faster to construct a String, call parse, than to use BigInteger
_numberLong = Long.parseLong(numStr);
_numTypesValid = NR_LONG;
} else {
// nope, need the heavy guns... (rare case)
_numberBigInt = new BigInteger(numStr);
_numTypesValid = NR_BIGINT;
}
} catch (NumberFormatException nex) {
// Can this ever occur? Due to overflow, maybe?
_wrapError("Malformed numeric value '"+numStr+"'", nex);
}
}
示例2: contentsAsDecimal
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
/**
* Convenience method for converting contents of the buffer
* into a {@link BigDecimal}.
*/
public BigDecimal contentsAsDecimal() throws NumberFormatException
{
// Already got a pre-cut array?
if (_resultArray != null) {
return NumberInput.parseBigDecimal(_resultArray);
}
// Or a shared buffer?
if ((_inputStart >= 0) && (_inputBuffer != null)) {
return NumberInput.parseBigDecimal(_inputBuffer, _inputStart, _inputLen);
}
// Or if not, just a single buffer (the usual case)
if ((_segmentSize == 0) && (_currentSegment != null)) {
return NumberInput.parseBigDecimal(_currentSegment, 0, _currentSize);
}
// If not, let's just get it aggregated...
return NumberInput.parseBigDecimal(contentsAsArray());
}
示例3: testIntParsing
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
public void testIntParsing() throws Exception
{
char[] testChars = "123456789".toCharArray();
assertEquals(3, NumberInput.parseInt(testChars, 2, 1));
assertEquals(123, NumberInput.parseInt(testChars, 0, 3));
assertEquals(2345, NumberInput.parseInt(testChars, 1, 4));
assertEquals(9, NumberInput.parseInt(testChars, 8, 1));
assertEquals(456789, NumberInput.parseInt(testChars, 3, 6));
assertEquals(23456, NumberInput.parseInt(testChars, 1, 5));
assertEquals(123456789, NumberInput.parseInt(testChars, 0, 9));
testChars = "32".toCharArray();
assertEquals(32, NumberInput.parseInt(testChars, 0, 2));
testChars = "189".toCharArray();
assertEquals(189, NumberInput.parseInt(testChars, 0, 3));
testChars = "10".toCharArray();
assertEquals(10, NumberInput.parseInt(testChars, 0, 2));
assertEquals(0, NumberInput.parseInt(testChars, 1, 1));
}
示例4: testLongBoundsChecks
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
public void testLongBoundsChecks() throws Exception
{
String minLong = String.valueOf(Long.MIN_VALUE).substring(1);
String maxLong = String.valueOf(Long.MAX_VALUE);
final String VALUE_491 = "1323372036854775807"; // is within range (JACKSON-491)
final String OVERFLOW = "9999999999999999999"; // and this one is clearly out
assertTrue(NumberInput.inLongRange(minLong, true));
assertTrue(NumberInput.inLongRange(maxLong, false));
assertTrue(NumberInput.inLongRange(VALUE_491, true));
assertTrue(NumberInput.inLongRange(VALUE_491, false));
assertFalse(NumberInput.inLongRange(OVERFLOW, false));
assertFalse(NumberInput.inLongRange(OVERFLOW, true));
char[] cbuf = minLong.toCharArray();
assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, true));
cbuf = maxLong.toCharArray();
assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, false));
cbuf = VALUE_491.toCharArray();
assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, true));
assertTrue(NumberInput.inLongRange(cbuf, 0, cbuf.length, false));
cbuf = OVERFLOW.toCharArray();
assertFalse(NumberInput.inLongRange(cbuf, 0, cbuf.length, true));
assertFalse(NumberInput.inLongRange(cbuf, 0, cbuf.length, false));
}
示例5: parse
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
public Date parse(String paramString, ParsePosition paramParsePosition)
{
if (looksLikeISO8601(paramString))
return parseAsISO8601(paramString, paramParsePosition);
int i = paramString.length();
int j;
do
{
i--;
if (i < 0)
break;
j = paramString.charAt(i);
}
while (((j < 48) || (j > 57)) && ((i <= 0) && (j == 45)));
if ((i < 0) && (NumberInput.inLongRange(paramString, false)))
return new Date(Long.parseLong(paramString));
return parseAsRFC1123(paramString, paramParsePosition);
}
示例6: _parseSlowInt
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
private void _parseSlowInt(int expType, char[] buf, int offset, int len)
throws IOException, JsonParseException
{
String numStr = _textBuffer.contentsAsString();
try {
// [JACKSON-230] Some long cases still...
if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) {
// Probably faster to construct a String, call parse, than to use BigInteger
_numberLong = Long.parseLong(numStr);
_numTypesValid = NR_LONG;
} else {
// nope, need the heavy guns... (rare case)
_numberBigInt = new BigInteger(numStr);
_numTypesValid = NR_BIGINT;
}
} catch (NumberFormatException nex) {
// Can this ever occur? Due to overflow, maybe?
_wrapError("Malformed numeric value '"+numStr+"'", nex);
}
}
示例7: convertNumberToBigDecimal
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
protected void convertNumberToBigDecimal()
throws IOException, JsonParseException
{
/* 05-Aug-2008, tatus: Important note: this MUST start with
* more accurate representations, since we don't know which
* value is the original one (others get generated when
* requested)
*/
if ((_numTypesValid & NR_DOUBLE) != 0) {
/* Let's actually parse from String representation,
* to avoid rounding errors that non-decimal floating operations
* would incur
*/
_numberBigDecimal = NumberInput.parseBigDecimal(getText());
} else if ((_numTypesValid & NR_BIGINT) != 0) {
_numberBigDecimal = new BigDecimal(_numberBigInt);
} else if ((_numTypesValid & NR_LONG) != 0) {
_numberBigDecimal = BigDecimal.valueOf(_numberLong);
} else if ((_numTypesValid & NR_INT) != 0) {
_numberBigDecimal = BigDecimal.valueOf(_numberInt);
} else {
_throwInternal();
}
_numTypesValid |= NR_BIGDECIMAL;
}
示例8: _parseSlowIntValue
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
private void _parseSlowIntValue(int expType, char[] buf, int offset, int len)
throws IOException, JsonParseException
{
String numStr = _textBuffer.contentsAsString();
try {
// [JACKSON-230] Some long cases still...
if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) {
// Probably faster to construct a String, call parse, than to use BigInteger
_numberLong = Long.parseLong(numStr);
_numTypesValid = NR_LONG;
} else {
// nope, need the heavy guns... (rare case)
_numberBigInt = new BigInteger(numStr);
_numTypesValid = NR_BIGINT;
}
} catch (NumberFormatException nex) {
// Can this ever occur? Due to overflow, maybe?
_wrapError("Malformed numeric value '"+numStr+"'", nex);
}
}
示例9: rangeCheckedLong
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
private Long rangeCheckedLong(JsonParser parser, DeserializationContext context)
throws IOException {
String text = parser.getText().trim();
if (text.length() == 0) {
return null;
}
try {
return Long.valueOf(NumberInput.parseLong(text));
}
catch (Exception e) {
throw context.weirdStringException(//NOSONAR
_valueClass,
"Over/underflow: numeric value (" + text +") out of range of Long ("
+ Long.MIN_VALUE + " to " + Long.MAX_VALUE + ")"
);
}
}
示例10: _parseLongPrimitive
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
protected final long _parseLongPrimitive(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) {
return jp.getLongValue();
}
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if (text.length() == 0) {
return 0L;
}
try {
return NumberInput.parseLong(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid long value");
}
if (t == JsonToken.VALUE_NULL) {
return 0L;
}
throw ctxt.mappingException(_valueClass, t);
}
示例11: parse
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public Date parse(String dateStr, ParsePosition pos)
{
if (looksLikeISO8601(dateStr)) { // also includes "plain"
return parseAsISO8601(dateStr, pos);
}
/* 14-Feb-2010, tatu: As per [JACKSON-236], better also
* consider "stringified" simple time stamp
*/
int i = dateStr.length();
while (--i >= 0) {
char ch = dateStr.charAt(i);
if (ch < '0' || ch > '9') break;
}
if (i < 0) { // all digits
if (NumberInput.inLongRange(dateStr, false)) {
return new Date(Long.parseLong(dateStr));
}
}
// Otherwise, fall back to using RFC 1123
return parseAsRFC1123(dateStr, pos);
}
示例12: getValueAsInt
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public int getValueAsInt(int defaultValue) throws IOException, JsonParseException
{
if (_currToken != null) {
switch (_currToken) {
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
return getIntValue();
case VALUE_TRUE:
return 1;
case VALUE_FALSE:
case VALUE_NULL:
return 0;
case VALUE_STRING:
return NumberInput.parseAsInt(getText(), defaultValue);
case VALUE_EMBEDDED_OBJECT:
{
Object value = this.getEmbeddedObject();
if (value instanceof Number) {
return ((Number) value).intValue();
}
}
}
}
return defaultValue;
}
示例13: getValueAsLong
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public long getValueAsLong(long defaultValue) throws IOException, JsonParseException
{
if (_currToken != null) {
switch (_currToken) {
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
return getLongValue();
case VALUE_TRUE:
return 1;
case VALUE_FALSE:
case VALUE_NULL:
return 0;
case VALUE_STRING:
return NumberInput.parseAsLong(getText(), defaultValue);
case VALUE_EMBEDDED_OBJECT:
{
Object value = this.getEmbeddedObject();
if (value instanceof Number) {
return ((Number) value).longValue();
}
}
}
}
return defaultValue;
}
示例14: getValueAsDouble
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
@Override
public double getValueAsDouble(double defaultValue) throws IOException, JsonParseException
{
if (_currToken != null) {
switch (_currToken) {
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
return getDoubleValue();
case VALUE_TRUE:
return 1;
case VALUE_FALSE:
case VALUE_NULL:
return 0;
case VALUE_STRING:
return NumberInput.parseAsDouble(getText(), defaultValue);
case VALUE_EMBEDDED_OBJECT:
{
Object value = this.getEmbeddedObject();
if (value instanceof Number) {
return ((Number) value).doubleValue();
}
}
}
}
return defaultValue;
}
示例15: _parseIndex
import com.fasterxml.jackson.core.io.NumberInput; //导入依赖的package包/类
private final static int _parseIndex(String str) {
final int len = str.length();
// [core#133]: beware of super long indexes; assume we never
// have arrays over 2 billion entries so ints are fine.
if (len == 0 || len > 10) {
return -1;
}
// [core#176]: no leading zeroes allowed
char c = str.charAt(0);
if (c <= '0') {
return (len == 1 && c == '0') ? 0 : -1;
}
if (c > '9') {
return -1;
}
for (int i = 1; i < len; ++i) {
c = str.charAt(i);
if (c > '9' || c < '0') {
return -1;
}
}
if (len == 10) {
long l = NumberInput.parseLong(str);
if (l > Integer.MAX_VALUE) {
return -1;
}
}
return NumberInput.parseInt(str);
}