in aws-android-sdk-appsync-runtime/src/main/java/com/apollographql/apollo/internal/json/BufferedSourceJsonReader.java [893:956]
private int nextNonWhitespace(boolean throwOnEof) throws IOException {
/*
* This code uses ugly local variables 'p' and 'l' representing the 'pos'
* and 'limit' fields respectively. Using locals rather than fields saves
* a few field reads for each whitespace character in a pretty-printed
* document, resulting in a 5% speedup. We need to flush 'p' to its field
* before any (potentially indirect) call to fillBuffer() and reread both
* 'p' and 'l' after any (potentially indirect) call to the same method.
*/
int p = 0;
while (source.request(p + 1)) {
int c = buffer.getByte(p++);
if (c == '\n' || c == ' ' || c == '\r' || c == '\t') {
continue;
}
buffer.skip(p - 1);
if (c == '/') {
if (!source.request(2)) {
return c;
}
checkLenient();
byte peek = buffer.getByte(1);
switch (peek) {
case '*':
// skip a /* c-style comment */
buffer.readByte(); // '/'
buffer.readByte(); // '*'
if (!skipTo("*/")) {
throw syntaxError("Unterminated comment");
}
buffer.readByte(); // '*'
buffer.readByte(); // '/'
p = 0;
continue;
case '/':
// skip a // end-of-line comment
buffer.readByte(); // '/'
buffer.readByte(); // '/'
skipToEndOfLine();
p = 0;
continue;
default:
return c;
}
} else if (c == '#') {
// Skip a # hash end-of-line comment. The JSON RFC doesn't specify this behaviour, but it's
// required to parse existing documents.
checkLenient();
skipToEndOfLine();
p = 0;
} else {
return c;
}
}
if (throwOnEof) {
throw new EOFException("End of input");
} else {
return -1;
}
}