CSVParser implements Iterable<CSVRecord>, Closeable { public void close() throws IOException { if (this.lexer != null) { this.lexer.close(); } } CSVParser(final Reader reader, final CSVFormat format); static CSVParser parse(File file, final CSVFormat format); static CSVParser parse(String string, final CSVFormat format); static CSVParser parse(URL url, Charset charset, final CSVFormat format); void close(); long getCurrentLineNumber(); Map<String, Integer> getHeaderMap(); long getRecordNumber(); List<CSVRecord> getRecords(); boolean isClosed(); Iterator<CSVRecord> iterator();  }
@Test(expected = NoSuchElementException.class) public void testClose() throws Exception { final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z"); final CSVParser parser = CSVFormat.DEFAULT.withCommentStart('#').withHeader().parse(in); final Iterator<CSVRecord> records = parser.iterator(); assertTrue(records.hasNext()); parser.close(); assertFalse(records.hasNext()); records.next(); }
@Test(expected = IllegalArgumentException.class) public void testInvalidFormat() throws Exception { final CSVFormat invalidFormat = CSVFormat.DEFAULT.withDelimiter(CR); new CSVParser(null, invalidFormat).close(); }