Connecting Apama Applications to External Components > Using Standard Adapters > Using the Apama File Adapter > 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.getUnique();
 
//read using JCSVCodec
openCSVFileRead.codec := "JCSVCodec";
 
//file to read
openCSVFileRead.filename := "/usr/home/formby/stocktick.csv";
 
//separator char is a ","
openCSVFileRead.payload["separator"] := ",";
 
//emit event to channel in config.
emit 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 plug-in.
Copyright © 2013-2015 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.