Developing Apama Applications > Developing Adapters > Standard Apama Adapters > Apama File adapter > Opening fixed width files
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.getUnique();
 
//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"] := "_";
 
//emit event to channel in config.
emit 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 plug-in.
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.