private static Object[] splitLine(String line,Pattern delim,char quote,BufferedReader in,int numColumns) throws IOException {
  List<String> tokens=new ArrayList<String>();
  StringBuilder sb=new StringBuilder();
  Matcher m=delim.matcher(line);
  int idx=0;
  while (idx < line.length()) {
    if (line.charAt(idx) == quote) {
      sb.setLength(0);
      ++idx;
      while (true) {
        int endIdx=line.indexOf(quote,idx);
        if (endIdx >= 0) {
          sb.append(line,idx,endIdx);
          ++endIdx;
          if ((endIdx < line.length()) && (line.charAt(endIdx) == quote)) {
            sb.append(quote);
            idx=endIdx + 1;
          }
 else {
            idx=endIdx;
            break;
          }
        }
 else {
          sb.append(line,idx,line.length());
          sb.append(LINE_SEPARATOR);
          idx=0;
          line=in.readLine();
          if (line == null) {
            throw new EOFException("Missing end of quoted value " + sb);
          }
        }
      }
      tokens.add(sb.toString());
      idx=(m.find(idx) ? m.end() : line.length());
    }
 else     if (m.find(idx)) {
      tokens.add(line.substring(idx,m.start()));
      idx=m.end();
    }
 else {
      tokens.add(line.substring(idx));
      idx=line.length();
    }
  }
  return tokens.toArray(new Object[Math.max(tokens.size(),numColumns)]);
}

private static Object [ ] splitLine ( String line , Pattern delim , char quote , BufferedReader in , int numColumns ) throws IOException { List < String > tokens = new ArrayList < String > ( ) ; StringBuilder sb = new StringBuilder ( ) ; Matcher m = delim . matcher ( line ) ; int idx = 0 ; while ( idx < line . length ( ) ) { if ( line . charAt ( idx ) == quote ) { sb . setLength ( 0 ) ; ++ idx ; while ( true ) { int endIdx = line . indexOf ( quote , idx ) ; if ( endIdx >= 0 ) { sb . append ( line , idx , endIdx ) ; ++ endIdx ; if ( ( endIdx < line . length ( ) ) && ( line . charAt ( endIdx ) == quote ) ) { sb . append ( quote ) ; idx = endIdx + 1 ; } else { idx = endIdx ; break ; } } else { sb . append ( line , idx , line . length ( ) ) ; sb . append ( LINE_SEPARATOR ) ; idx = 0 ; line = in . readLine ( ) ; if ( line == null ) { throw new EOFException ( "Missing end of quoted value " + sb ) ; } } } tokens . add ( sb . toString ( ) ) ; idx = ( m . find ( idx ) ? m . end ( ) : line . length ( ) ) ; } else if ( m . find ( idx ) ) { tokens . add ( line . substring ( idx , m . start ( ) ) ) ; idx = m . end ( ) ; } else { tokens . add ( line . substring ( idx ) ) ; idx = line . length ( ) ; } } return tokens . toArray ( new Object [ Math . max ( tokens . size ( ) , numColumns ) ] ) ; }
splits the given line using the given delimiter pattern and quote character . may read additional lines for quotes spanning newlines .
