1 package com.opencsv.bean.concurrent;
2
3 import com.opencsv.CSVReader;
4 import com.opencsv.bean.CsvToBean;
5 import com.opencsv.exceptions.CsvValidationException;
6 import org.apache.commons.lang3.StringUtils;
7
8 import java.io.IOException;
9
10
11
12
13
14
15
16
17 public class SingleLineReader {
18 protected final CSVReader csvReader;
19 protected final boolean ignoreEmptyLines;
20
21
22 protected String[] line;
23
24
25
26
27
28
29 public SingleLineReader(CSVReader csvReader, boolean ignoreEmptyLines) {
30 this.csvReader = csvReader;
31 this.ignoreEmptyLines = ignoreEmptyLines;
32 }
33
34 private boolean isCurrentLineEmpty() {
35 return line.length == 0 || (line.length == 1 && StringUtils.isEmpty(line[0]));
36 }
37
38
39
40
41
42
43
44
45
46
47 public String[] readNextLine() throws IOException, CsvValidationException {
48 do {
49 line = csvReader.readNext();
50 } while (line != null && isCurrentLineEmpty() && ignoreEmptyLines);
51 return getLine();
52 }
53
54
55
56
57 public long getLinesRead() {return csvReader.getLinesRead();}
58
59
60
61
62
63 public String[] getLine() {
64 String[] lineCopy = line;
65 if(line != null) {
66 lineCopy = new String[line.length];
67 System.arraycopy(line, 0, lineCopy, 0, line.length);
68 }
69 return lineCopy;
70 }
71 }