Source:
<code>private int readCSVFile(CommandLine cl, DcmDir main, int num) throws Exception { if (!cl.hasOption("record-config")) throw new MissingOptionException("Missing record-config option."); String delim = cl.hasOption("csv-delim") ? cl.getOptionValue("csv-delim") : ","; String quote = cl.hasOption("csv-quote") && !cl.getOptionValue("csv-quote").equals("") ? cl.getOptionValue("csv-quote") : "\""; BufferedReader br = null; try { br = new BufferedReader(new FileReader(cl.getOptionValue("csv"))); loadDefaultConfiguration(cl.getOptionValue("record-config")); String headerline = br.readLine(); String[] headers = headerline.split(delim); List<Integer> tags = new ArrayList<Integer>(); List<VR> vrs = new ArrayList<VR>(); for (int i = 0; i < headers.length; i++) { String header = headers[i].replaceAll(quote, ""); int tag = DICT.tagForKeyword(header); tags.add(tag); vrs.add(DICT.vrOf(tag)); } String nextLine; while((nextLine = br.readLine()) != null) { <START> String escq = new StringBuilder().append("\\").append(quote).toString(); <END> String regex = delim + "(?=(?:[^" + escq + "]*" + escq + "[^" + escq + "]*" + escq + ")*[^" + escq + "]*$)"; String[] values = nextLine.split(regex, -1); if (values.length > headers.length) { LOG.warn("Number of values in line " + nextLine + " does not match number of headers"); return num; } num = main.addReferenceToNextLine( tags.toArray(new Integer[tags.size()]), vrs.toArray(new VR[vrs.size()]), values, num, quote); } } finally { if (br != null) br.close(); } return num; }</code><technical_language>Performance: Build this string while loop. for next line. (String regex). (By way: a StringBuilder here, for next line? I a StringBuilder in this case. Java automatically replaces a type of string concatenation a StringBuilder in compiled bytecode.)</technical_language>

Target:
private int readCSVFile(CommandLine cl, DcmDir main, int num) throws Exception { if (!cl.hasOption("record-config")) throw new MissingOptionException("Missing record-config option."); String delim = cl.hasOption("csv-delim") ? cl.getOptionValue("csv-delim") : ","; String quote = cl.hasOption("csv-quote") && !cl.getOptionValue("csv-quote").equals("") ? cl.getOptionValue("csv-quote") : "\""; BufferedReader br = null; try { br = new BufferedReader(new FileReader(cl.getOptionValue("csv"))); loadDefaultConfiguration(cl.getOptionValue("record-config")); String headerline = br.readLine(); String[] headers = headerline.split(delim); List<Integer> tags = new ArrayList<Integer>(); List<VR> vrs = new ArrayList<VR>(); for (int i = 0; i < headers.length; i++) { String header = headers[i].replaceAll(quote, ""); int tag = DICT.tagForKeyword(header); tags.add(tag); vrs.add(DICT.vrOf(tag)); } String nextLine; String esc = "\\"; String escq = esc.concat(quote); String regex = delim + "(?=(?:[^" + escq + "]*" + escq + "[^" + escq + "]*" + escq + ")*[^" + escq + "]*$)"; Pattern p = Pattern.compile(regex); while((nextLine = br.readLine()) != null) { String[] values = p.split(nextLine, -1); if (values.length > headers.length) { LOG.warn("Number of values in line " + nextLine + " does not match number of headers"); return num; } num = main.addReferenceToNextLine( tags.toArray(new Integer[tags.size()]), vrs.toArray(new VR[vrs.size()]), values, num, quote); } } finally { if (br != null) br.close(); } return num; }