in hollow-jsonadapter/src/main/java/com/netflix/hollow/jsonadapter/chunker/JsonArrayChunker.java [68:114]
public Reader nextChunk() throws IOException {
while(!currentSegment.nextSpecialCharacter()) {
if(!nextSegment())
return null;
}
if(currentSegment.specialCharacter() != '{')
throw new IllegalStateException("Bad json");
int nestedObjectCount = 1;
JsonArrayChunkReader chunkReader = new JsonArrayChunkReader(currentSegment, currentSegment.specialCharacterIteratorPosition());
boolean insideQuotes = false;
long lastEscapeCharacterLocation = Long.MIN_VALUE;
while(nestedObjectCount > 0) {
while(!currentSegment.nextSpecialCharacter()) {
if(!nextSegment())
throw new IllegalStateException("Bad json");
chunkReader.addSegment(currentSegment);
}
switch(currentSegment.specialCharacter()) {
case '{':
if(!insideQuotes)
nestedObjectCount++;
break;
case '}':
if(!insideQuotes)
nestedObjectCount--;
break;
case '\"':
long currentLocation = currentSegmentStartOffset + currentSegment.specialCharacterIteratorPosition();
if(lastEscapeCharacterLocation != (currentLocation - 1)) {
insideQuotes = !insideQuotes;
}
break;
case '\\':
currentLocation = currentSegmentStartOffset + currentSegment.specialCharacterIteratorPosition();
if(lastEscapeCharacterLocation != (currentLocation - 1))
lastEscapeCharacterLocation = currentLocation;
break;
}
}
chunkReader.setEndOffset(currentSegment.specialCharacterIteratorPosition() + 1);
return chunkReader;
}