Apama 10.15.2 | Connecting Apama Applications to External Components | Standard IAF Plug-ins | The File IAF Adapter (JMultiFileTransport) | Opening comma separated values (CSV) files
 
Opening comma separated values (CSV) files
An example of defining an OpenFileForReading event that opens a CSV file so that each field is automatically parsed appears below. The additional data required by the CSV codec is stored in the payload dictionary.
com.apama.file.OpenFileForReading openCSVFileRead :=
new com.apama.file.OpenFileForReading;
 
//matches transport in IAF config
openCSVFileRead.transportName := JMultiFileTransport;
 
//the request id to use
openCSVFileRead.requestId := integer.incrementCounter("FileTransport.requestId");
 
//read using JCSVCodec
openCSVFileRead.codec := "JCSVCodec";
 
//file to read
openCSVFileRead.filename := "/usr/home/formby/stocktick.csv";
 
//separator char is a ","
openCSVFileRead.payload["separator"] := ",";
 
//send event to channel in config.
send openCSVFileRead 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 CSV codec, see The CSV codec IAF plug-in.