@@ -122,22 +122,14 @@ public CSVParser(String input, CSVFormat format) throws IOException {
122122 }
123123
124124 /**
125- * Parses the CSV input according to the given format and returns the content as an array of {@link CSVRecord}
126- * entries.
125+ * Returns the current line number in the input stream.
127126 * <p/>
128- * The returned content starts at the current parse-position in the stream.
127+ * ATTENTION: in case your csv has multiline-values the returned number does not correspond to the record-number
129128 *
130- * @return list of {@link CSVRecord} entries, may be empty
131- * @throws IOException
132- * on parse error or input read-failure
129+ * @return current line number
133130 */
134- public List <CSVRecord > getRecords () throws IOException {
135- List <CSVRecord > records = new ArrayList <CSVRecord >();
136- CSVRecord rec ;
137- while ((rec = getRecord ()) != null ) {
138- records .add (rec );
139- }
140- return records ;
131+ public int getLineNumber () {
132+ return lexer .getLineNumber ();
141133 }
142134
143135 /**
@@ -189,6 +181,25 @@ CSVRecord getRecord() throws IOException {
189181 return result ;
190182 }
191183
184+ /**
185+ * Parses the CSV input according to the given format and returns the content as an array of {@link CSVRecord}
186+ * entries.
187+ * <p/>
188+ * The returned content starts at the current parse-position in the stream.
189+ *
190+ * @return list of {@link CSVRecord} entries, may be empty
191+ * @throws IOException
192+ * on parse error or input read-failure
193+ */
194+ public List <CSVRecord > getRecords () throws IOException {
195+ List <CSVRecord > records = new ArrayList <CSVRecord >();
196+ CSVRecord rec ;
197+ while ((rec = getRecord ()) != null ) {
198+ records .add (rec );
199+ }
200+ return records ;
201+ }
202+
192203 /**
193204 * Initializes the name to index mapping if the format defines a header.
194205 */
@@ -226,6 +237,14 @@ public Iterator<CSVRecord> iterator() {
226237 return new Iterator <CSVRecord >() {
227238 private CSVRecord current ;
228239
240+ private CSVRecord getNextRecord () {
241+ try {
242+ return getRecord ();
243+ } catch (IOException e ) {
244+ throw new RuntimeException (e );
245+ }
246+ }
247+
229248 public boolean hasNext () {
230249 if (current == null ) {
231250 current = getNextRecord ();
@@ -249,28 +268,9 @@ public CSVRecord next() {
249268 return next ;
250269 }
251270
252- private CSVRecord getNextRecord () {
253- try {
254- return getRecord ();
255- } catch (IOException e ) {
256- throw new RuntimeException (e );
257- }
258- }
259-
260271 public void remove () {
261272 throw new UnsupportedOperationException ();
262273 }
263274 };
264275 }
265-
266- /**
267- * Returns the current line number in the input stream.
268- * <p/>
269- * ATTENTION: in case your csv has multiline-values the returned number does not correspond to the record-number
270- *
271- * @return current line number
272- */
273- public int getLineNumber () {
274- return lexer .getLineNumber ();
275- }
276276}
0 commit comments