File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
src/org/rascalmpl/library/lang/json/internal Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -1160,8 +1160,11 @@ public IValue read(Reader in, Type expected) throws IOException {
11601160 * current position in the buffer.
11611161 */
11621162 public static class OriginTrackingReader extends FilterReader {
1163+ // offset is always pointing at the point in the file where JsonReader.pos == 0
11631164 private int offset = 0 ;
1165+ // limit is always pointing to the amount of no-junk characters in the underlying buffer below buffer.length
11641166 private int limit = 0 ;
1167+ // readCount increases by 1 with every call to `read`
11651168 private int readCount = 0 ;
11661169
11671170 protected OriginTrackingReader (Reader in ) {
@@ -1170,16 +1173,19 @@ protected OriginTrackingReader(Reader in) {
11701173
11711174 @ Override
11721175 public int read (char [] cbuf , int off , int len ) throws IOException {
1173- // we've read until here before we were reset to 0.
1174- offset += limit ;
1176+ // we've read until here before we were reset to starting point `off`.
1177+ // the offset of the new current 0-based buffer starts here:
1178+ offset += limit - off ;
11751179
1176- // get the new limit
1177- limit = in .read (cbuf , off , len );
1180+ var charsRead = in .read (cbuf , off , len );
1181+
1182+ // get the new limit (to where we've filled the buffer)
1183+ limit = charsRead + off ;
11781184
11791185 readCount ++;
11801186
1181- // and return it .
1182- return limit ;
1187+ // and return the number of characters read .
1188+ return charsRead ;
11831189 }
11841190
11851191 public int getLimitOffset () {
You can’t perform that action at this time.
0 commit comments