12
12
* Low-level helper class that handles actual output of CSV, purely
13
13
* based on indexes given without worrying about reordering etc.
14
14
*/
15
- public final class CsvWriter
15
+ public class CsvWriter
16
16
{
17
17
/* As an optimization we try coalescing short writes into
18
18
* buffer; but pass longer directly.
@@ -50,6 +50,8 @@ public final class CsvWriter
50
50
51
51
final protected int _cfgLineSeparatorLength ;
52
52
53
+ protected int _cfgMaxQuoteCheckChars ;
54
+
53
55
/**
54
56
* Lowest-valued character that is safe to output without using
55
57
* quotes around value
@@ -136,6 +138,8 @@ public CsvWriter(IOContext ctxt, Writer out,
136
138
_cfgLineSeparatorLength = linefeed .length ;
137
139
138
140
_cfgMinSafeChar = _calcSafeChar ();
141
+
142
+ _cfgMaxQuoteCheckChars = MAX_QUOTE_CHECK ;
139
143
}
140
144
141
145
public CsvWriter (CsvWriter base , CsvSchema newSchema )
@@ -145,6 +149,7 @@ public CsvWriter(CsvWriter base, CsvSchema newSchema)
145
149
_bufferRecyclable = base ._bufferRecyclable ;
146
150
_outputEnd = base ._outputEnd ;
147
151
_out = base ._out ;
152
+ _cfgMaxQuoteCheckChars = base ._cfgMaxQuoteCheckChars ;
148
153
149
154
_cfgColumnSeparator = newSchema .getColumnSeparator ();
150
155
_cfgQuoteCharacter = newSchema .getQuoteChar ();
@@ -187,7 +192,7 @@ public int nextColumnIndex() {
187
192
/**********************************************************
188
193
*/
189
194
190
- public void write (int columnIndex , String value ) throws IOException
195
+ public final void write (int columnIndex , String value ) throws IOException
191
196
{
192
197
// easy case: all in order
193
198
if (columnIndex == _nextColumnToWrite ) {
@@ -198,13 +203,13 @@ public void write(int columnIndex, String value) throws IOException
198
203
_buffer (columnIndex , BufferedValue .buffered (value ));
199
204
}
200
205
201
- public void write (int columnIndex , char [] ch , int offset , int len ) throws IOException
206
+ public final void write (int columnIndex , char [] ch , int offset , int len ) throws IOException
202
207
{
203
208
// !!! TODO: optimize
204
209
write (columnIndex , new String (ch , offset , len ));
205
210
}
206
211
207
- public void write (int columnIndex , int value ) throws IOException
212
+ public final void write (int columnIndex , int value ) throws IOException
208
213
{
209
214
// easy case: all in order
210
215
if (columnIndex == _nextColumnToWrite ) {
@@ -215,7 +220,7 @@ public void write(int columnIndex, int value) throws IOException
215
220
_buffer (columnIndex , BufferedValue .buffered (value ));
216
221
}
217
222
218
- public void write (int columnIndex , long value ) throws IOException
223
+ public final void write (int columnIndex , long value ) throws IOException
219
224
{
220
225
// easy case: all in order
221
226
if (columnIndex == _nextColumnToWrite ) {
@@ -226,7 +231,7 @@ public void write(int columnIndex, long value) throws IOException
226
231
_buffer (columnIndex , BufferedValue .buffered (value ));
227
232
}
228
233
229
- public void write (int columnIndex , float value ) throws IOException
234
+ public final void write (int columnIndex , float value ) throws IOException
230
235
{
231
236
// easy case: all in order
232
237
if (columnIndex == _nextColumnToWrite ) {
@@ -237,7 +242,7 @@ public void write(int columnIndex, float value) throws IOException
237
242
_buffer (columnIndex , BufferedValue .buffered (value ));
238
243
}
239
244
240
- public void write (int columnIndex , double value ) throws IOException
245
+ public final void write (int columnIndex , double value ) throws IOException
241
246
{
242
247
// easy case: all in order
243
248
if (columnIndex == _nextColumnToWrite ) {
@@ -249,7 +254,7 @@ public void write(int columnIndex, double value) throws IOException
249
254
}
250
255
251
256
252
- public void write (int columnIndex , boolean value ) throws IOException
257
+ public final void write (int columnIndex , boolean value ) throws IOException
253
258
{
254
259
// easy case: all in order
255
260
if (columnIndex == _nextColumnToWrite ) {
@@ -260,7 +265,7 @@ public void write(int columnIndex, boolean value) throws IOException
260
265
_buffer (columnIndex , BufferedValue .buffered (value ));
261
266
}
262
267
263
- public void writeColumnName (String name ) throws IOException
268
+ public final void writeColumnName (String name ) throws IOException
264
269
{
265
270
appendValue (name );
266
271
++_nextColumnToWrite ;
@@ -572,14 +577,14 @@ public void close(boolean autoClose) throws IOException
572
577
* Helper method that determines whether given String is likely
573
578
* to require quoting; check tries to optimize for speed.
574
579
*/
575
- protected final boolean _mayNeedQuotes (String value , int length )
580
+ protected boolean _mayNeedQuotes (String value , int length )
576
581
{
577
582
// 21-Mar-2014, tatu: If quoting disabled, don't quote
578
583
if (_cfgQuoteCharacter < 0 ) {
579
584
return false ;
580
585
}
581
586
// let's not bother checking long Strings, just quote already:
582
- if (length > MAX_QUOTE_CHECK ) {
587
+ if (length > _cfgMaxQuoteCheckChars ) {
583
588
return true ;
584
589
}
585
590
for (int i = 0 ; i < length ; ++i ) {
@@ -599,7 +604,7 @@ protected void _buffer(int index, BufferedValue v)
599
604
_buffered [index ] = v ;
600
605
}
601
606
602
- protected final void _flushBuffer () throws IOException
607
+ protected void _flushBuffer () throws IOException
603
608
{
604
609
if (_outputTail > 0 ) {
605
610
_charsWritten += _outputTail ;
0 commit comments