code: private int readToBuf(int toRead) throws IOException {
      long startTime = System.currentTimeMillis();
      if (toRead < 0) {
        toRead = (maxPacketReadLen > 0 ? maxPacketReadLen : buf.capacity())
                 - buf.limit();
      }
      
      int nRead = in.read(buf.array(), buf.limit(), toRead);
      
      if (nRead < 0) {
        throw new EOFException("while trying to read " + toRead + " bytes");
      }
      bufRead = buf.limit() + nRead;
      buf.limit(bufRead);
      long readToBufDuration = System.currentTimeMillis() - startTime;
      // We keep track of the time required to read 'nRead' bytes of data.
      // We track small reads and large reads separately.
      if (nRead > KB_RIGHT_SHIFT_MIN) {
        datanode.myMetrics.largeReadsToBufRate.inc(
            (int) (nRead >> KB_RIGHT_SHIFT_BITS),
            readToBufDuration);
      } else {
        datanode.myMetrics.smallReadsToBufRate.inc(nRead, readToBufDuration);
      }
      datanode.myMetrics.readToBufBytesRead.inc(nRead);
      return nRead;
    }
docs: reads upto toRead byte to buf at buf.limit() and increments the limit.
  throws an IOException if read does not succeed.