int readPartition(ByteSequencesReader reader) throws IOException {
    long start = System.currentTimeMillis();
    if (valueLength != -1) {
      int limit = ramBufferSize.bytes / valueLength;
      for(int i=0;i<limit;i++) {
        BytesRef item = null;
        try {
          item = reader.next();
        } catch (Throwable t) {
          verifyChecksum(t, reader);
        }
        if (item == null) {
          break;
        }
        buffer.append(item);
      }
    } else {
      while (true) {
        BytesRef item = null;
        try {
          item = reader.next();
        } catch (Throwable t) {
          verifyChecksum(t, reader);
        }
        if (item == null) {
          break;
        }
        buffer.append(item);
        // Account for the created objects.
        // (buffer slots do not account to buffer size.) 
        if (bufferBytesUsed.get() > ramBufferSize.bytes) {
          break;
        }
      }
    }
    sortInfo.readTime += System.currentTimeMillis() - start;
    return buffer.size();
  }