code: private int readCustomLine(Text str, int maxLineLength, int maxBytesToConsume)
      throws IOException {
      str.clear();
      int txtLength = 0; // tracks str.getLength(), as an optimization
      long bytesConsumed = 0;
      int delPosn = 0;
      do {
        int startPosn = bufferPosn; // starting from where we left off the last
        // time
        if (bufferPosn >= bufferLength) {
          startPosn = bufferPosn = 0;
          bufferLength = in.read(buffer);
          if (bufferLength <= 0)
            break; // EOF
        }
        for (; bufferPosn < bufferLength; ++bufferPosn) {
          if (buffer[bufferPosn] == recordDelimiterBytes[delPosn]) {
            delPosn++;
            if (delPosn >= recordDelimiterBytes.length) {
              bufferPosn++;
              break;
            }
          } else {
            delPosn = 0;
          }
        }
        int readLength = bufferPosn - startPosn;
        bytesConsumed += readLength;
        int appendLength = readLength - delPosn;
        if (appendLength > maxLineLength - txtLength) {
          appendLength = maxLineLength - txtLength;
        }
        if (appendLength > 0) {
          str.append(buffer, startPosn, appendLength);
          txtLength += appendLength;
        }
      } while (delPosn < recordDelimiterBytes.length
        && bytesConsumed < maxBytesToConsume);
      if (bytesConsumed > (long) Integer.MAX_VALUE)
        throw new IOException("Too many bytes before delimiter: " + bytesConsumed);
      return (int) bytesConsumed;
    }
docs: Read a line terminated by a custom delimiter.