1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.opencsv;
17
18
19 import com.opencsv.enums.CSVReaderNullFieldIndicator;
20 import org.apache.commons.lang3.ObjectUtils;
21
22 import java.util.Locale;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 public class CSVParserBuilder {
38
39 private char separator = ICSVParser.DEFAULT_SEPARATOR;
40 private char quoteChar = ICSVParser.DEFAULT_QUOTE_CHARACTER;
41 private char escapeChar = ICSVParser.DEFAULT_ESCAPE_CHARACTER;
42 private boolean strictQuotes = ICSVParser.DEFAULT_STRICT_QUOTES;
43 private boolean ignoreLeadingWhiteSpace = ICSVParser.DEFAULT_IGNORE_LEADING_WHITESPACE;
44 private boolean ignoreQuotations = ICSVParser.DEFAULT_IGNORE_QUOTATIONS;
45 private CSVReaderNullFieldIndicator nullFieldIndicator = CSVReaderNullFieldIndicator.NEITHER;
46 private Locale errorLocale = Locale.getDefault();
47
48
49
50
51
52 public CSVParserBuilder() {
53 }
54
55
56
57
58
59
60
61 public CSVParserBuilder withSeparator(
62 final char separator) {
63 this.separator = separator;
64 return this;
65 }
66
67
68
69
70
71
72
73
74 public CSVParserBuilder withQuoteChar(
75 final char quoteChar) {
76 this.quoteChar = quoteChar;
77 return this;
78 }
79
80
81
82
83
84
85
86
87 public CSVParserBuilder withEscapeChar(
88 final char escapeChar) {
89 this.escapeChar = escapeChar;
90 return this;
91 }
92
93
94
95
96
97
98
99
100
101 public CSVParserBuilder withStrictQuotes(
102 final boolean strictQuotes) {
103 this.strictQuotes = strictQuotes;
104 return this;
105 }
106
107
108
109
110
111
112
113
114 public CSVParserBuilder withIgnoreLeadingWhiteSpace(
115 final boolean ignoreLeadingWhiteSpace) {
116 this.ignoreLeadingWhiteSpace = ignoreLeadingWhiteSpace;
117 return this;
118 }
119
120
121
122
123
124
125
126 public CSVParserBuilder withIgnoreQuotations(
127 final boolean ignoreQuotations) {
128 this.ignoreQuotations = ignoreQuotations;
129 return this;
130 }
131
132
133
134
135
136
137 public CSVParser build() {
138
139 return new CSVParser(
140 separator,
141 quoteChar,
142 escapeChar,
143 strictQuotes,
144 ignoreLeadingWhiteSpace,
145 ignoreQuotations,
146 nullFieldIndicator,
147 errorLocale);
148 }
149
150
151
152
153 public char getSeparator() {
154 return separator;
155 }
156
157
158
159
160 public char getQuoteChar() {
161 return quoteChar;
162 }
163
164
165
166
167 public char getEscapeChar() {
168 return escapeChar;
169 }
170
171
172
173
174 public boolean isStrictQuotes() {
175 return strictQuotes;
176 }
177
178
179
180
181 public boolean isIgnoreLeadingWhiteSpace() {
182 return ignoreLeadingWhiteSpace;
183 }
184
185
186
187
188 public boolean isIgnoreQuotations() {
189 return ignoreQuotations;
190 }
191
192
193
194
195
196
197
198 public CSVParserBuilder withFieldAsNull(final CSVReaderNullFieldIndicator fieldIndicator) {
199 this.nullFieldIndicator = fieldIndicator;
200 return this;
201 }
202
203
204
205
206
207
208
209
210 public CSVParserBuilder withErrorLocale(Locale errorLocale) {
211 this.errorLocale = ObjectUtils.defaultIfNull(errorLocale, Locale.getDefault());
212 return this;
213 }
214
215
216
217
218 public CSVReaderNullFieldIndicator nullFieldIndicator() {
219 return nullFieldIndicator;
220 }
221
222 }