code: private int countNonNewline(char[] cbuf, int off, int len) {
      for(int cnt = 0; cnt < len; cnt++) {
        final int pos = off + cnt;
        if(cbuf[pos] == UNIX_NEWLINE) {
          return cnt;
        }
        if(cbuf[pos] == CARRIAGE_RETURN) {
          return cnt;
        }
      }
      return len;
    }
docs: Count the number of non-newline characters before first newline in the string.
  
  @param cbuf character buffer
  @param off offset
  @param len length
  @return number of non-newline characters