CsvUtils { public static String[] tokenizeCsvData(String csvData) { String[] tokens = null; if (csvData != null) { CsvReader csvReader = getCsvReader(new StringReader(csvData)); try { if (csvReader.readRecord()) { tokens = csvReader.getValues(); } } catch (IOException e) { } } return tokens; }  static CsvReader getCsvReader(Reader reader); static CsvReader getCsvReaderDquote(Reader reader); static String[] tokenizeCsvData(String csvData); static String escapeCsvData(String data); static String escapeAndQuoteCsvData(String data); static String escapeCsvData(String[] data); static String escapeCsvData(String[] data, char recordDelimiter, char textQualifier); static String escapeCsvData(String[] data, char recordDelimiter, char textQualifier, int escapeMode); static String escapeCsvData(String[] data, char recordDelimiter, char textQualifier, int escapeMode, String nullString); static int write(Writer writer, String... data); static void writeSql(String sql, Writer writer); static void writeBsh(String script, Writer writer); static void writeLineFeed(Writer writer); static final String DELIMITER; static final String LINE_SEPARATOR; }
@Test public void testLineFeedsInCsv() { String line = "\"test\",\"line\nfeed\""; String[] tokens = CsvUtils.tokenizeCsvData(line); assertEquals("test", tokens[0]); assertEquals("line\nfeed", tokens[1]); }
@Test public void testLastElementIsNull() { String[] tokens = CsvUtils.tokenizeCsvData("\"01493931\",\"0\",\"01493931\",,\"UktNQzIxMAD String expectedNull = tokens[tokens.length-1]; assertNull("Expected null. Instead received: " + expectedNull, expectedNull); }