CsvReader extends LineNumberReader { public List<String[]> readStringRecords() throws IOException { ArrayList<String[]> vector = new ArrayList<String[]>(256); String[] record; while ((record = readRecord()) != null) { vector.add(record); } vector.trimToSize(); return vector; } CsvReader(Reader reader, char[] separators);  CsvReader(Reader reader, char[] separators, boolean ignoreEmptyLines, String commentPrefix); final char[] getSeparators(); final boolean ignoresEmptyLines(); final String getCommentPrefix(); String[] readRecord(); double[] readDoubleRecord(); List<String[]> readStringRecords(); List<double[]> readDoubleRecords();  }
@Test public void testReadAllRecords() throws IOException { CsvReader reader = createReader(CSV_DATA, '|'); List<String[]> records = reader.readStringRecords(); assertEquals(EXPECTED_RECORDS.length, records.size()); for (int i = 0; i < records.size(); i++) { assertArrayEquals(EXPECTED_RECORDS[i], records.get(i)); } }
@Test public void testMultipleSeparators() throws Exception { CsvReader reader = createReader("a$b|c\nd$$\n|$i", '|', '$'); List<String[]> records = reader.readStringRecords(); assertEquals(3, records.size()); assertArrayEquals(new String[]{"a", "b", "c"}, records.get(0)); assertArrayEquals(new String[]{"d", "", ""}, records.get(1)); assertArrayEquals(new String[]{"", "", "i"}, records.get(2)); }
@Test public void testSemicolonSeparator() throws Exception { CsvReader reader = createReader("a; b;c\nd;;\n;; i \n", ';'); List<String[]> records = reader.readStringRecords(); assertEquals(3, records.size()); assertArrayEquals(new String[]{"a", "b", "c"}, records.get(0)); assertArrayEquals(new String[]{"d", "", ""}, records.get(1)); assertArrayEquals(new String[]{"", "", "i"}, records.get(2)); }
@Test public void testTabSeparator() throws Exception { CsvReader reader = createReader("a\tb\tc\nd\t\t\n\t\ti", '\t'); List<String[]> records = reader.readStringRecords(); assertEquals(3, records.size()); assertArrayEquals(new String[]{"a", "b", "c"}, records.get(0)); assertArrayEquals(new String[]{"d", "", ""}, records.get(1)); assertArrayEquals(new String[]{"", "", "i"}, records.get(2)); }
@Test public void testSpaceSeparator() throws Exception { CsvReader reader = createReader(" a b c\nd \n i", ' '); List<String[]> records = reader.readStringRecords(); assertEquals(3, records.size()); assertArrayEquals(new String[]{"a", "b", "c"}, records.get(0)); assertArrayEquals(new String[]{"d"}, records.get(1)); assertArrayEquals(new String[]{"i"}, records.get(2)); }
@Test public void testWhitespaceSeparators() throws Exception { String csv = "\n CsvReader reader = createReader(csv, false, null, '\t', ' '); List<String[]> records = reader.readStringRecords(); assertEquals(9, records.size()); assertArrayEquals(new String[]{}, records.get(0)); assertArrayEquals(new String[]{" assertArrayEquals(new String[]{}, records.get(2)); assertArrayEquals(new String[]{"a", "b", "c"}, records.get(3)); assertArrayEquals(new String[]{}, records.get(4)); assertArrayEquals(new String[]{"d"}, records.get(5)); assertArrayEquals(new String[]{"i"}, records.get(6)); assertArrayEquals(new String[]{}, records.get(7)); assertArrayEquals(new String[]{}, records.get(8)); }
@Test public void testWhitespaceSeparatorIgnoringComments() throws Exception { String csv = "\n CsvReader reader = createReader(csv, false, " List<String[]> records = reader.readStringRecords(); assertEquals(8, records.size()); assertArrayEquals(new String[]{}, records.get(0)); assertArrayEquals(new String[]{}, records.get(1)); assertArrayEquals(new String[]{"a", "b", "c"}, records.get(2)); assertArrayEquals(new String[]{}, records.get(3)); assertArrayEquals(new String[]{"d"}, records.get(4)); assertArrayEquals(new String[]{"i"}, records.get(5)); assertArrayEquals(new String[]{}, records.get(6)); assertArrayEquals(new String[]{}, records.get(7)); }
@Test public void testWhitespaceSeparatorsIgnoringEmptyLines() throws Exception { String csv = "\n CsvReader reader = createReader(csv, true, null, '\t', ' '); List<String[]> records = reader.readStringRecords(); assertEquals(4, records.size()); assertArrayEquals(new String[]{" assertArrayEquals(new String[]{"a", "b", "c"}, records.get(1)); assertArrayEquals(new String[]{"d"}, records.get(2)); assertArrayEquals(new String[]{"i"}, records.get(3)); }
@Test public void testWhitespaceSeparatorsIgnoringEmptyLinesAndComments() throws Exception { String csv = "\n CsvReader reader = createReader(csv, true, " List<String[]> records = reader.readStringRecords(); assertEquals(3, records.size()); assertArrayEquals(new String[]{"a", "b", "c"}, records.get(0)); assertArrayEquals(new String[]{"d"}, records.get(1)); assertArrayEquals(new String[]{"i"}, records.get(2)); }