Reads throw the buffer up to the given index, filling the buffer from the underlying stream if
necessary. Returns -1 if the underlying stream terminates before the given offset can be
reached.
771135
private int bufferedPeek(final int offset) throws IOException {
    if (buffer.size() > offset) {
      // We've got enough of the file in memory already, we just pull from the buffer
      final ListIterator<Integer> iterator = buffer.listIterator(offset);
      return iterator.next();
    }
    // We don't have enough in the buffer to peek... Read until we do, then recurse.
    while (buffer.size() <= offset) {
      final int current = in.read();
      if (current < 0)
        return -1;
      buffer.add(current);
    }
    // Buffer should now be full enough to answer the request.
    return bufferedPeek(offset);
  }
914211
@Override
  public int read(byte []buffer, int offset, int length)
    throws IOException
  {
    int sublen = _next.read(buffer, offset, length);
    
    if (sublen <= 0) {
      return 0;
    }
    
    _crc = Crc64.generate(_crc, buffer, offset, sublen);
    
    _length += sublen;
    
    return sublen;
  }
1114836
@Override
  public int read(byte []buf, int offset, int len) throws IOException
  {
    int available = _available;
    
    // The chunk still has more data left
    if (available > 0) {
      len = Math.min(len, available);

      len = _next.read(buf, offset, len);

      if (len > 0) {
        _available -= len;
      }
    }
    // The chunk is done, so read the next chunk
    else if (available == 0) {
      _available = readChunkLength();

      // the new chunk has data
      if (_available > 0) {
        len = Math.min(len, _available);

        len = _next.read(buf, offset, len);

        if (len > 0)
          _available -= len;
      }
      // the new chunk is the last
      else {
        _available = -1;
        len = -1;
      }
    }
    else {
      len = -1;
    }
    
    return len;
  }
992456
public int read(char buff[], int off, int len) throws IOException
    {
        int b = read();
        if ( b == -1 )
            return -1;  // EOF, not zero read apparently
        else {
            buff[off]=(char)b;
            return 1;
        }
    }
40668
public int read()
    throws IOException
  {
    if (_byteHead == _byteTail) {
      return -1;
    }

    int b = _byteBuffer[_byteTail] & 0xff;
    _byteTail = (_byteTail + 1) % _byteBuffer.length;

    return b;
  }
333579
int read() throws IOException {
        int nextInt = -1;
        if (!hasSplit) {
            split();
        }
        if (beforeDoctype != null) {
            nextInt = beforeDoctype.read();
            if (nextInt == -1) {
                beforeDoctype = null;
            }
        }
        if (nextInt == -1 && decl != null) {
            nextInt = decl.read();
            if (nextInt == -1) {
                decl = null;
            }
        }
        if (nextInt == -1 && afterDoctype != null) {
            nextInt = afterDoctype.read();
            if (nextInt == -1) {
                afterDoctype = null;
            }
        }
        if (nextInt == -1) {
            nextInt = original.read();
        }
        return nextInt;
    }
197254
public int read(byte []buf, int offset, int length) throws IOException
  {
    try {
      return readInt(buf, offset, length);
    } catch (IOException e) {
      _isKeepalive = false;
      throw e;
    } catch (RuntimeException e) {
      _isKeepalive = false;
      throw e;
    }
  }
540975
@Override
	public int read(byte[] buffer, int offset, int len) throws IOException {
		return this.in.read(buffer, offset, len);
	}
573554
public int read(char []buf, int offset, int length)
    throws IOException
  {
    for (int i = 0; i < length; i++) {
      int ch = is.read();

      if (ch < 0)
        return i > 0 ? i : -1;
      else {
        buf[offset + i] = (char) ch;
      }
    }
      
    return length;
  }
744130
@Override
  public int read () throws IOException
  {
    _ensureOpen ();
    while (true)
    {
      if (m_nNextCharIndex >= m_nChars)
      {
        _fill ();
        if (m_nNextCharIndex >= m_nChars)
          return -1;
      }
      if (m_bSkipLF)
      {
        m_bSkipLF = false;
        if (m_aBuf[m_nNextCharIndex] == '\n')
        {
          m_nNextCharIndex++;
          continue;
        }
      }
      return m_aBuf[m_nNextCharIndex++];
    }
  }
869680
private int read1(char[] cbuf, int off, int len) throws IOException {
        if (nextChar >= nChars) {
            /* If the requested length is at least as large as the buffer, and
               if there is no mark/reset activity, and if line feeds are not
               being skipped, do not bother to copy the characters into the
               local buffer.  In this way buffered streams will cascade
               harmlessly. */
            if (len >= cb.length && markedChar <= UNMARKED && !skipLF) {
                return in.read(cbuf, off, len);
            }
            fill();
        }
        if (nextChar >= nChars) return -1;
        if (skipLF) {
            skipLF = false;
            if (cb[nextChar] == '\n') {
                nextChar++;
                if (nextChar >= nChars)
                    fill();
                if (nextChar >= nChars)
                    return -1;
            }
        }
        int n = Math.min(len, nChars - nextChar);
        System.arraycopy(cb, nextChar, cbuf, off, n);
        nextChar += n;
        return n;
    }
1321038
@Override
  public int read(byte []buf, int offset, int length) throws IOException
  {
    try {
      if (_is == null) {
        if (_s == null) {
          return -1;
        }
        
        _is = _s.getInputStream();
      }

      int readLength = _is.read(buf, offset, length);

      if (readLength >= 0) {
        _totalReadBytes += readLength;
      }

      return readLength;
    } catch (InterruptedIOException e) {
      e.printStackTrace();
      if (_throwReadInterrupts)
        throw e;
      
      log.log(Level.FINEST, e.toString(), e);
    } catch (IOException e) {
      e.printStackTrace();
      if (_throwReadInterrupts) {
        throw e;
      }

      if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, e.toString(), e);
      }
      else {
        log.finer(e.toString());
      }
      // server/0611
      /*
      try {
        close();
      } catch (IOException e1) {
      }
      */
    }

    return -1;
  }
150375
public int read(byte []buf, int offset, int length)
    throws IOException
  {
    try {
      if (_s == null || _is == null)
        return -1;

      int readLength = _is.read(buf, offset, length);

      if (readLength >= 0)
        _totalReadBytes += readLength;

      return readLength;
    } catch (InterruptedIOException e) {
      if (_throwReadInterrupts)
        throw e;
      
      log.log(Level.FINEST, e.toString(), e);
    } catch (IOException e) {
      if (_throwReadInterrupts)
        throw e;

      log.log(Level.FINER, e.toString(), e);
    }

    return -1;
  }
577824
public synchronized int read(byte b[], int off, int len) throws IOException
    {
        int avail=_avail-_pos;
        if (avail <=0)
        {
            fill();
            avail=_avail-_pos;
        }

        if (avail <=0)
            len=-1;
        else
        {
            len=(avail < len) ? avail : len;
            System.arraycopy(_buf,_pos,b,off,len);
            _pos +=len;
        }
        
        return len;
    }
698708
protected final int readBytesAt(int offset)
        throws IOException
    {
        // shouldn't modify mBytePtr, assumed to be 'offset'
        if (mIn != null) {
            int count = mIn.read(mByteBuffer, offset, mByteBuffer.length - offset);
            if (count > 0) {
                mByteBufferEnd += count;
            }
            return count;
        }
        return -1;
    }
984435
public int read(byte[] array, int offset, int length) {
		if(curr==null)return -1;
		int len;
		int count=0;
		while(length>0) { // loop through while there's data needed
			if((len=curr.remaining())>length) { //  if enough data in curr buffer, use this code
				curr.get(array,offset,length);
				count+=length;
				length=0;
			} else {  // get data from curr, mark how much is needed to fulfil, and loop for next curr.
				curr.get(array,offset,len);
				count+=len;
				offset+=len;
				length-=len;
				if(idx<bbs.size()) {
					curr=bbs.get(idx++);
				} else {
					length=0; // stop, and return the count of how many we were able to load
				}
			}
		}
		return count;
	}
993511
@Override
    public int read()
        throws IOException
    {
        synchronized ( lock )
        {
            ensureOpen();
            if ( next >= length )
                return -1;
            return seq.charAt( next++ );
        }
    }