@@ -274,19 +274,17 @@ public final static boolean loadMore(JsonIterator iter) throws IOException {
274274 }
275275
276276 private static boolean keepSkippedBytesThenRead (JsonIterator iter ) throws IOException {
277- int n ;
278- int offset ;
277+ int offset = iter .tail - iter .skipStartedAt ;
278+ byte [] srcBuffer = iter .buf ;
279+ // Double the size of internal buffer
280+ // TODO: Fix NegativeArraySizeException that happens if source stream doesnt return as much
281+ // of output as was requested i.e. when n < iter.buf.length - offset. Anyhow doubling the buffer
282+ // size seems to be pretty dangerous idea and should be either disabled or solved safely.
279283 if (iter .skipStartedAt == 0 || iter .skipStartedAt < iter .tail / 2 ) {
280- byte [] newBuf = new byte [iter .buf .length * 2 ];
281- offset = iter .tail - iter .skipStartedAt ;
282- System .arraycopy (iter .buf , iter .skipStartedAt , newBuf , 0 , offset );
283- iter .buf = newBuf ;
284- n = iter .in .read (iter .buf , offset , iter .buf .length - offset );
285- } else {
286- offset = iter .tail - iter .skipStartedAt ;
287- System .arraycopy (iter .buf , iter .skipStartedAt , iter .buf , 0 , offset );
288- n = iter .in .read (iter .buf , offset , iter .buf .length - offset );
284+ iter .buf = new byte [iter .buf .length * 2 ];
289285 }
286+ System .arraycopy (srcBuffer , iter .skipStartedAt , iter .buf , 0 , offset );
287+ int n = iter .in .read (iter .buf , offset , iter .buf .length - offset );
290288 iter .skipStartedAt = 0 ;
291289 if (n < 1 ) {
292290 if (n == -1 ) {
0 commit comments