code: public int read(byte b[], int off, int len) throws IOException
    {
      int total = 0;
      while (total < len) {
        int avail = count - pos;
        if (avail <= 0) {
          fill();
          avail = count - pos;
          if(avail <= 0) {
            if (total > 0)
              return total;
            else
              return -1;
          }
        }
        int copy = Math.min(len - total, avail);
        System.arraycopy(buf, pos, b, off + total, copy);
        pos += copy;
        total += copy;
      }
      return total;
    }
docs: Implement buffering on top of the <code>read</code> method of
  the wrapped <code>ServletInputStream</code>.
  
  @param      b     the buffer into which the data is read.
  @param      off   the start offset of the data.
  @param      len   the maximum number of bytes read.
  @return     the total number of bytes read into the buffer, or
  <code>-1</code> if there is no more data because the end
  of the stream has been reached.
  @exception  IOException  if an I/O error occurs.