Scenario 2: Utilizing Output Stream to save filtered data to a local file - 6.1

Talend Components Reference Guide

EnrichVersion
6.1
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

Based on the preceding scenario, this scenario saves the filtered data to a local file using output stream.

Dropping and linking components

  1. Drop tJava from the Palette to the design workspace.

  2. Connect tJava to tFileInputDelimited using a Trigger > On Subjob OK connection.

Configuring the components

  1. Double-click tJava to open its Basic settings view.

  2. In the Code area, type in the following command:

    new java.io.File("C:/myFolder").mkdirs(); 
    globalMap.put("out_file",new
    java.io.FileOutputStream("C:/myFolder/customerselection.txt",false));

    Note

    In this scenario, the command we use in the Code area of tJava will create a new folder C:/myFolder where the output file customerselection.txt will be saved. You can customize the command in accordance with actual practice.

  3. Double-click tFileOutputDelimited to open its Basic settings view.

  4. Select Use Output Stream check box to enable the Output Stream field in which you can define the output stream using command.

    Fill in the Output Stream field with following command:

    (java.io.OutputStream)globalMap.get("out_file")

    Note

    You can customize the command in the Output Stream field by pressing CTRL+SPACE to select built-in command from the list or type in the command into the field manually in accordance with actual practice. In this scenario, the command we use in the Output Stream field will call the java.io.OutputStream class to output the filtered data stream to a local file which is defined in the Code area of tJava in this scenario.

  5. Click Sync columns to retrieve the schema defined in the preceding component.

  6. Leave rest of the components as they were in the previous scenario.

Saving and executing the Job

  1. Press Ctrl+S to save your Job.

  2. Press F6 or click Run on the Run tab to execute the Job.

    The three specified columns Id, CustomerName and CustomerAddress are output in the defined output file.

For an example of how to use dynamic schemas with tFileOutputDelimited, see Scenario 4: Writing dynamic columns from a MySQL database to an output file.