Esempio n. 1
0
 private int fillBuf() throws IOException {
   if (storeEnd != 0) {
     int storeLen = storeEnd - storeBegin;
     if (storeLen > 0) {
       // there is some store data
       if (storeLen == buf.length) {
         // buffer is full, double the capacity
         char[] doubleBuf = Arrays.copyOf(buf, 2 * buf.length);
         bufferPool.recycle(buf);
         buf = doubleBuf;
       } else {
         // Left shift all the stored data to make space
         System.arraycopy(buf, storeBegin, buf, 0, storeLen);
         storeEnd = storeLen;
         storeBegin = 0;
         bufferOffset += readBegin - storeEnd;
       }
     } else {
       storeBegin = storeEnd = 0;
       bufferOffset += readBegin;
     }
   } else {
     bufferOffset += readBegin;
   }
   // Fill the rest of the buf
   return reader.read(buf, storeEnd, buf.length - storeEnd);
 }
Esempio n. 2
0
 @Override
 public void close() throws IOException {
   reader.close();
   bufferPool.recycle(buf);
 }
Esempio n. 3
0
 JsonTokenizer(Reader reader, BufferPool bufferPool) {
   this.reader = reader;
   this.bufferPool = bufferPool;
   buf = bufferPool.take();
 }