Package org.supercsv.encoder
Class SelectiveCsvEncoder
- java.lang.Object
-
- org.supercsv.encoder.DefaultCsvEncoder
-
- org.supercsv.encoder.SelectiveCsvEncoder
-
- All Implemented Interfaces:
CsvEncoder
public class SelectiveCsvEncoder extends DefaultCsvEncoder
A selective CsvEncoder implementation - only the desired column numbers (if any) are encoded. Use with caution - disabling encoding may increase performance but at the risk of invalid CSV.- Since:
- 2.1.0
- Author:
- James Bassett
-
-
Constructor Summary
Constructors Constructor Description SelectiveCsvEncoder(boolean[] columnsToEncode)
Constructs a new SelectiveCsvEncoder that encodes columns if the element representing that column in the supplied array is true.SelectiveCsvEncoder(int... columnsToEncode)
Constructs a new SelectiveCsvEncoder that encodes columns by column number.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
encode(java.lang.String input, CsvContext context, CsvPreference preference)
Encodes a String to be written to a CSV file.
-
-
-
Constructor Detail
-
SelectiveCsvEncoder
public SelectiveCsvEncoder(int... columnsToEncode)
Constructs a new SelectiveCsvEncoder that encodes columns by column number. If no column numbers are supplied (i.e. no parameters) then no columns will be encoded.- Parameters:
columnsToEncode
- the column numbers to encode
-
SelectiveCsvEncoder
public SelectiveCsvEncoder(boolean[] columnsToEncode)
Constructs a new SelectiveCsvEncoder that encodes columns if the element representing that column in the supplied array is true.- Parameters:
columnsToEncode
- boolean array representing columns to encode (true indicates a column should be encoded).
-
-
Method Detail
-
encode
public java.lang.String encode(java.lang.String input, CsvContext context, CsvPreference preference)
Encodes a String to be written to a CSV file. The encoder should honour all CSV preferences including updating the current lineNumber (in the CSV context - it will be updated in the calling CsvWriter after encoding has completed) as line terminators are encountered in the String to be escaped (converting all 3 variations of line terminators to the end of line symbols specified in the preferences). The CsvContext can also be used to encode based on the current context (e.g. you may want to always put quotes around a particular column).- Specified by:
encode
in interfaceCsvEncoder
- Overrides:
encode
in classDefaultCsvEncoder
- Parameters:
input
- the String to be encodedcontext
- the contextpreference
- the CSV preferences- Returns:
- the encoded CSV
-
-