Ensures that a token is ready. After this call either token or value will be non-null. To ensure token has a definitive value, use #peek()
()
| 352 | * value, use {@link #peek()} |
| 353 | */ |
| 354 | private JsonToken quickPeek() throws IOException { |
| 355 | if (hasToken) { |
| 356 | return token; |
| 357 | } |
| 358 | |
| 359 | switch (peekStack()) { |
| 360 | case EMPTY_DOCUMENT: |
| 361 | if (lenient) { |
| 362 | consumeNonExecutePrefix(); |
| 363 | } |
| 364 | replaceTop(JsonScope.NONEMPTY_DOCUMENT); |
| 365 | JsonToken firstToken = nextValue(); |
| 366 | if (!lenient && firstToken != JsonToken.BEGIN_ARRAY && firstToken != JsonToken.BEGIN_OBJECT) { |
| 367 | syntaxError("Expected JSON document to start with '[' or '{'"); |
| 368 | } |
| 369 | return firstToken; |
| 370 | case EMPTY_ARRAY: |
| 371 | return nextInArray(true); |
| 372 | case NONEMPTY_ARRAY: |
| 373 | return nextInArray(false); |
| 374 | case EMPTY_OBJECT: |
| 375 | return nextInObject(true); |
| 376 | case DANGLING_NAME: |
| 377 | return objectValue(); |
| 378 | case NONEMPTY_OBJECT: |
| 379 | return nextInObject(false); |
| 380 | case NONEMPTY_DOCUMENT: |
| 381 | try { |
| 382 | JsonToken token = nextValue(); |
| 383 | if (lenient) { |
| 384 | return token; |
| 385 | } |
| 386 | throw syntaxError("Expected EOF"); |
| 387 | } catch (EOFException e) { |
| 388 | hasToken = true; // TODO: avoid throwing here? |
| 389 | return token = JsonToken.END_DOCUMENT; |
| 390 | } |
| 391 | case CLOSED: |
| 392 | throw new IllegalStateException("JsonReader is closed"); |
| 393 | default: |
| 394 | throw new AssertionError(); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Consumes the non-execute prefix if it exists. |
no test coverage detected