17
17
import com .google .api .client .json .JsonFactory ;
18
18
import com .google .api .client .json .JsonParser ;
19
19
import com .google .api .client .json .JsonToken ;
20
- import com .google .api .client .util .Preconditions ;
21
20
import com .google .gson .stream .JsonReader ;
22
21
import java .io .EOFException ;
23
22
import java .io .IOException ;
@@ -44,8 +43,7 @@ class GsonParser extends JsonParser {
44
43
GsonParser (GsonFactory factory , JsonReader reader ) {
45
44
this .factory = factory ;
46
45
this .reader = reader ;
47
- // lenient to allow top-level values of any type
48
- reader .setLenient (true );
46
+ reader .setLenient (false );
49
47
}
50
48
51
49
@ Override
@@ -69,56 +67,58 @@ public JsonFactory getFactory() {
69
67
}
70
68
71
69
@ Override
72
- public byte getByteValue () {
70
+ public byte getByteValue () throws IOException {
73
71
checkNumber ();
74
72
return Byte .parseByte (currentText );
75
73
}
76
74
77
75
@ Override
78
- public short getShortValue () {
76
+ public short getShortValue () throws IOException {
79
77
checkNumber ();
80
78
return Short .parseShort (currentText );
81
79
}
82
80
83
81
@ Override
84
- public int getIntValue () {
82
+ public int getIntValue () throws IOException {
85
83
checkNumber ();
86
84
return Integer .parseInt (currentText );
87
85
}
88
86
89
87
@ Override
90
- public float getFloatValue () {
88
+ public float getFloatValue () throws IOException {
91
89
checkNumber ();
92
90
return Float .parseFloat (currentText );
93
91
}
94
92
95
93
@ Override
96
- public BigInteger getBigIntegerValue () {
94
+ public BigInteger getBigIntegerValue () throws IOException {
97
95
checkNumber ();
98
96
return new BigInteger (currentText );
99
97
}
100
98
101
99
@ Override
102
- public BigDecimal getDecimalValue () {
100
+ public BigDecimal getDecimalValue () throws IOException {
103
101
checkNumber ();
104
102
return new BigDecimal (currentText );
105
103
}
106
104
107
105
@ Override
108
- public double getDoubleValue () {
106
+ public double getDoubleValue () throws IOException {
109
107
checkNumber ();
110
108
return Double .parseDouble (currentText );
111
109
}
112
110
113
111
@ Override
114
- public long getLongValue () {
112
+ public long getLongValue () throws IOException {
115
113
checkNumber ();
116
114
return Long .parseLong (currentText );
117
115
}
118
116
119
- private void checkNumber () {
120
- Preconditions .checkArgument (
121
- currentToken == JsonToken .VALUE_NUMBER_INT || currentToken == JsonToken .VALUE_NUMBER_FLOAT );
117
+ private void checkNumber () throws IOException {
118
+ if (currentToken != JsonToken .VALUE_NUMBER_INT
119
+ && currentToken != JsonToken .VALUE_NUMBER_FLOAT ) {
120
+ throw new IOException ("Token is not a number" );
121
+ }
122
122
}
123
123
124
124
@ Override
0 commit comments