1 package com.opencsv;
2
3 import com.opencsv.enums.CSVReaderNullFieldIndicator;
4 import com.opencsv.processor.RowProcessor;
5 import com.opencsv.validators.LineValidatorAggregator;
6 import com.opencsv.validators.RowValidatorAggregator;
7 import org.apache.commons.lang3.ObjectUtils;
8
9 import java.io.Reader;
10 import java.util.Locale;
11
12
13
14
15
16
17
18
19 abstract public class CSVReaderBaseBuilder<T> {
20 protected final Reader reader;
21 protected final LineValidatorAggregator lineValidatorAggregator = new LineValidatorAggregator();
22 protected final RowValidatorAggregator rowValidatorAggregator = new RowValidatorAggregator();
23 private final CSVParserBuilder parserBuilder = new CSVParserBuilder();
24 protected int skipLines = CSVReader.DEFAULT_SKIP_LINES;
25 protected ICSVParser icsvParser = null;
26 protected boolean keepCR;
27 protected boolean verifyReader = CSVReader.DEFAULT_VERIFY_READER;
28 protected CSVReaderNullFieldIndicator nullFieldIndicator = CSVReaderNullFieldIndicator.NEITHER;
29 protected int multilineLimit = CSVReader.DEFAULT_MULTILINE_LIMIT;
30 protected Locale errorLocale = Locale.getDefault();
31 protected RowProcessor rowProcessor = null;
32
33
34
35
36
37
38 protected CSVReaderBaseBuilder(final Reader reader) {
39 this.reader = reader;
40 }
41
42
43
44
45
46
47 protected Reader getReader() {
48 return reader;
49 }
50
51
52
53
54
55
56 protected int getSkipLines() {
57 return skipLines;
58 }
59
60
61
62
63
64
65 protected ICSVParser getCsvParser() {
66 return icsvParser;
67 }
68
69
70
71
72
73
74 protected int getMultilineLimit() {
75 return multilineLimit;
76 }
77
78
79
80
81
82
83
84 protected boolean keepCarriageReturn() {
85 return this.keepCR;
86 }
87
88
89
90
91
92
93 protected ICSVParser getOrCreateCsvParser() {
94 return ObjectUtils.defaultIfNull(icsvParser,
95 parserBuilder
96 .withFieldAsNull(nullFieldIndicator)
97 .withErrorLocale(errorLocale)
98 .build());
99 }
100
101
102
103
104 public boolean isVerifyReader() {
105 return verifyReader;
106 }
107
108
109
110
111 public Locale getErrorLocale() {
112 return errorLocale;
113 }
114
115
116
117
118 public LineValidatorAggregator getLineValidatorAggregator() {
119 return lineValidatorAggregator;
120 }
121
122
123
124
125 public RowValidatorAggregator getRowValidatorAggregator() {
126 return rowValidatorAggregator;
127 }
128
129
130
131
132
133 public abstract T build();
134 }