The Fixed Width codec IAF plug-in
The Fixed Width codec plug-in (
JFixedWidthCodec) translates between fixed width data and a sequence of string values. This codec (or the CSV codec plug-in) can be used with the standard Apama File adapter to read data from files and write data to files. For more information on the CSV codec, see
The CSV codec IAF plug-in.
Fixed width data is a method of storing data fields in a packet or a line that is a fixed number of characters in size. Data stored in a fixed width format can be expressed by the following three parameters:
The field widths used (that is, the number of characters used for storing each field)
The padding character used if the data for a given field can be stored in less than the number of characters allocated for it
Whether or not the data is left or right aligned within the field.
For example, consider the following, which describes a tick with ordered properties:
symbol | 6 characters |
exchange | 4 characters |
current price | 9 characters |
day high | 9 characters |
day low | 9 characters |
If the pad character is -, an example of a left-aligned line is as follows:
TSCO--L---392.25---400.25---382.25---
The following is an example of a right-aligned line:
--TSCO---L---392.25---400.25---382.25
To specify fixed width data properties, do one of the following:
Set the fixed width properties in the IAF configuration file you use to start the adapter. For example, to obtain the left-aligned fixed width data above:
<property name="fieldLengths" value="[6,4,9,9,9]"/>
<property name="padCharacter" value="-"/>
<property name="isLeftAligned" value="true"/>
If you set all these properties, the codec uses them by default when decoding or encoding events.
If you do not set any of these properties, the codec expects to receive configuration events (as described in
Multiple configurations and the Fixed Width codec), prior to receiving messages to encode or decode. Otherwise, the codec refuses to process these 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.
If you require a default configuration, be sure to set all of these properties in the configuration file. If you set some of the properties, but not all of them, the codec cannot start.
For an example configuration file, see adapters\config\JFixedWidthCodec-example.xml.dist in the Apama installation directory. The JFixedWidthCodec-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.