Apama 10.15.0 | Connecting Apama Applications to External Components | Standard IAF Plug-ins | Codec IAF Plug-ins | The CSV codec IAF plug-in
 
The CSV codec IAF plug-in
 
Multiple configurations and the CSV codec
Decoding CSV data from the sink to send to the correlator
Encoding CSV data from the correlator for the sink
The CSV codec plug-in (JCSVCodec) translates between comma separated value (CSV) data and a sequence of string values. This codec (or the Fixed Width codec plug-in; see The Fixed Width codec IAF plug-in) can be used with the standard Apama File adapter to read data from files and to write data to files.
CSV format is a simple way to store data on a value by value basis. Consider an example CSV file that contains stock tick data. The lines in the file are ordered by Symbol, Exchange, Current Price, Day High, and Day Low, as follows:
TSCO, L, 395.50, 401.5, 386.25
MKS, L, 225.25, 240.75, 210.25
In this example, each field is separated from the next by a comma. You can use other characters as separators as long as you identify the separator character for the CSV codec.
To specify a separator character other than a comma, do one of the following:
*Send a configuration event from the transport that is communicating with the CSV codec using the method described in Multiple configurations and the CSV codec.
*Set the separator property in the IAF configuration file that you use to start the File adapter. For example:
<property name="separator" value="," />
If you set the separator property, the codec uses the separator you specify by default. If you do not specify the separator property, and the codec does not receive any configuration events before receiving messages to encode or decode, the codec refuses to process messages. The codec throws an exception back to the module that called it, which is either the transport or the semantic mapper depending on whether the data is flowing downstream or upstream.
Optionally, you can also set the excelCompatible property in the IAF configuration file. By default, this is set to false. If set to true, Excel compatibility mode is enabled, and double quotes are then used to match the behavior of Excel. The separator property is still required when using the excelCompatible property. For example:
<property name="separator" value="," />
<property name="excelCompatible" value="true" />
For an example configuration file, see adapters\config\JCSVCodec-example.xml.dist in the Apama installation directory. The JCSVCodec-example.xml.dist file itself should not be modified, but you can copy relevant sections of the XML code, modify the code as required for the purposes of your data, and then add the modified content to the adapter configuration file in which the codec is to be used.