MCPcopy Index your code
hub / github.com/google/gson / nextLong

Method nextLong

src/main/java/com/google/gson/stream/JsonReader.java:555–578  ·  view source on GitHub ↗

Returns the JsonToken#NUMBER long value of the next token, consuming it. If the next token is a string, this method will attempt to parse it as a long. If the next token's numeric value cannot be exactly represented by a Java long, this method throws. @throws IllegalStateException i

()

Source from the content-addressed store, hash-verified

553 * as a number, or exactly represented as a long.
554 */
555 public long nextLong() throws IOException {
556 quickPeek();
557 if (value == null) {
558 throw new IllegalStateException("Expected a long but was " + peek());
559 }
560
561 long result;
562 try {
563 result = Long.parseLong(value);
564 } catch (NumberFormatException ignored) {
565 double asDouble = Double.parseDouble(value); // don't catch this NumberFormatException
566 result = (long) asDouble;
567 if (result != asDouble) {
568 throw new NumberFormatException(value);
569 }
570 }
571
572 if (result >= 1L && value.startsWith("0")) {
573 throw new NumberFormatException("JSON forbids octal prefixes: " + value);
574 }
575
576 advance();
577 return result;
578 }
579
580 /**
581 * Returns the {@link JsonToken#NUMBER int} value of the next token,

Calls 3

quickPeekMethod · 0.95
peekMethod · 0.95
advanceMethod · 0.95