public static BufferedSourceJsonReader bufferedSourceJsonReader(BufferedSource bufferedSource) { return new BufferedSourceJsonReader(bufferedSource); } }
int c = nextNonWhitespace(true); return peeked = PEEKED_END_ARRAY; case ';': checkLenient(); // fall-through case ',': break; default: throw syntaxError("Unterminated array"); int c = nextNonWhitespace(true); return peeked = PEEKED_END_OBJECT; case ';': checkLenient(); // fall-through case ',': break; default: throw syntaxError("Unterminated object"); int c = nextNonWhitespace(true); switch (c) { case '"': checkLenient(); return peeked = PEEKED_SINGLE_QUOTED_NAME; case '}': throw syntaxError("Expected name");
@Override public String nextName() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } String result; if (p == PEEKED_UNQUOTED_NAME) { result = nextUnquotedValue(); } else if (p == PEEKED_DOUBLE_QUOTED_NAME) { result = nextQuotedValue(DOUBLE_QUOTE_OR_SLASH); } else if (p == PEEKED_SINGLE_QUOTED_NAME) { result = nextQuotedValue(SINGLE_QUOTE_OR_SLASH); } else { throw new JsonDataException("Expected a name but was " + peek() + " at path " + getPath()); } peeked = PEEKED_NONE; pathNames[stackSize - 1] = result; return result; }
@Override public void beginObject() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_BEGIN_OBJECT) { push(JsonScope.EMPTY_OBJECT); peeked = PEEKED_NONE; } else { throw new JsonDataException("Expected BEGIN_OBJECT but was " + peek() + " at path " + getPath()); } }
@SuppressWarnings("TypeParameterUnusedInFormals") @Override public <T> T nextNull() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_NULL) { peeked = PEEKED_NONE; pathIndices[stackSize - 1]++; return null; } else { throw new JsonDataException("Expected null but was " + peek() + " at path " + getPath()); } }
@Override public void skipValue() throws IOException { if (failOnUnknown) { throw new JsonDataException("Cannot skip unexpected " + peek() + " at " + getPath()); int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); push(JsonScope.EMPTY_ARRAY); count++; } else if (p == PEEKED_BEGIN_OBJECT) { push(JsonScope.EMPTY_OBJECT); count++; } else if (p == PEEKED_END_ARRAY) { count--; } else if (p == PEEKED_UNQUOTED_NAME || p == PEEKED_UNQUOTED) { skipUnquotedValue(); } else if (p == PEEKED_DOUBLE_QUOTED || p == PEEKED_DOUBLE_QUOTED_NAME) { skipQuotedValue(DOUBLE_QUOTE_OR_SLASH); } else if (p == PEEKED_SINGLE_QUOTED || p == PEEKED_SINGLE_QUOTED_NAME) { skipQuotedValue(SINGLE_QUOTE_OR_SLASH); } else if (p == PEEKED_NUMBER) { buffer.skip(peekedNumberLength);
BufferedSourceJsonReader jsonReader = null; try { jsonReader = new BufferedSourceJsonReader(source); jsonReader.beginObject(); jsonReader.endObject(); return Response.<W>builder(operation) .data(operation.wrapData(data)) } finally { if (jsonReader != null) { jsonReader.close();
checkLenient(); byte peek = buffer.getByte(1); switch (peek) { if (!skipTo("*/")) { throw syntaxError("Unterminated comment"); skipToEndOfLine(); p = 0; continue; checkLenient(); skipToEndOfLine(); p = 0; } else {
throw syntaxError("Unterminated escape sequence"); case 'u': if (!source.request(4)) { throw new EOFException("Unterminated escape sequence at path " + getPath()); result += (c - 'A' + 10); } else { throw syntaxError("\\u" + buffer.readUtf8(4)); if (!lenient) throw syntaxError("Invalid escape sequence: \\" + (char) escaped); return (char) escaped;
/** * Throws a new IO exception with the given message and a context snippet * with this reader's content. */ private JsonEncodingException syntaxError(String message) throws JsonEncodingException { throw new JsonEncodingException(message + " at path " + getPath()); }
@Override public boolean hasNext() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } return p != PEEKED_END_OBJECT && p != PEEKED_END_ARRAY; }
if (source.request(length + 1) && isLiteral(buffer.getByte(length))) { return PEEKED_NONE; // Don't match trues, falsey or nullsoft!
private boolean isLiteral(int c) throws IOException { switch (c) { case '/': case '\\': case ';': case '#': case '=': checkLenient(); // fall-through case '{': case '}': case '[': case ']': case ':': case ',': case ' ': case '\t': case '\f': case '\r': case '\n': return false; default: return true; } }
@Override public void endArray() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_END_ARRAY) { stackSize--; pathIndices[stackSize - 1]++; peeked = PEEKED_NONE; } else { throw new JsonDataException("Expected END_ARRAY but was " + peek() + " at path " + getPath()); } }
@Override public void skipValue() throws IOException { if (failOnUnknown) { throw new JsonDataException("Cannot skip unexpected " + peek() + " at " + getPath()); int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); push(JsonScope.EMPTY_ARRAY); count++; } else if (p == PEEKED_BEGIN_OBJECT) { push(JsonScope.EMPTY_OBJECT); count++; } else if (p == PEEKED_END_ARRAY) { count--; } else if (p == PEEKED_UNQUOTED_NAME || p == PEEKED_UNQUOTED) { skipUnquotedValue(); } else if (p == PEEKED_DOUBLE_QUOTED || p == PEEKED_DOUBLE_QUOTED_NAME) { skipQuotedValue(DOUBLE_QUOTE_OR_SLASH); } else if (p == PEEKED_SINGLE_QUOTED || p == PEEKED_SINGLE_QUOTED_NAME) { skipQuotedValue(SINGLE_QUOTE_OR_SLASH); } else if (p == PEEKED_NUMBER) { buffer.skip(peekedNumberLength);
@Override public void beginArray() throws IOException { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_BEGIN_ARRAY) { push(JsonScope.EMPTY_ARRAY); pathIndices[stackSize - 1] = 0; peeked = PEEKED_NONE; } else { throw new JsonDataException("Expected BEGIN_ARRAY but was " + peek() + " at path " + getPath()); } }
BufferedSourceJsonReader jsonReader = null; try { jsonReader = new BufferedSourceJsonReader(source); jsonReader.beginObject(); jsonReader.endObject(); return Response.<W>builder(operation) .data(operation.wrapData(data)) } finally { if (jsonReader != null) { jsonReader.close();
checkLenient(); byte peek = buffer.getByte(1); switch (peek) { if (!skipTo("*/")) { throw syntaxError("Unterminated comment"); skipToEndOfLine(); p = 0; continue; checkLenient(); skipToEndOfLine(); p = 0; } else {