Opening fixed width files
An example of defining an OpenFileForReading event that opens a fixed width file so that each field is automatically parsed appears below. The additional data required by the Fixed Width codec is stored in the payload dictionary.
com.apama.file.OpenFileForReading openFixedFileRead :=
new com.apama.file.OpenFileForReading;
//matches transport in IAF instance
openFixedFileRead.transportName := JMultiFileTransport;
//the request id to use
openFixedFileRead.requestId := integer.incrementCounter("FileTransport.requestId");
//read using CSV Codec
openFixedFileRead.codec := "JFixedWidthCodec";
//file to read
openFixedFileRead.filename := "/usr/home/formby/stocktick.txt";
//additional data required to interpret fixed width data
//sequence of field lengths
openFixedFileRead.payload["fieldLengths"] := "[6,4,9,9,9]";
//it is left aligned
openFixedFileRead.payload["isLeftAligned"] := "true";
//the pad character
openFixedFileRead.payload["padCharacter"] := "_";
//send event to channel in config.
send openFixedFileRead to "FILE";
Subsequently, when the File adapter receives FileLine events, the adapter stores each field in the data sequence in order. You can access the ones you are interested in.
For details about using the Fixed Width codec, see
The Fixed Width codec IAF plug-in.