This scenario describes a three-component Job that uses Java code through a tJavaFlex component to display the content of a file being transferred from the source to the target. As all the components in this Job support the dynamic schema feature, we can leverage this feature to save the time of configuring each column of the schema.
Drop tFileInputDelimited, tJavaFlex, and tFileOutputDelimited from the Palette onto the design workspace.
Connect the components in a series using Row > Main links.
Label the components according to their roles in the Job.
Double-click the tFileInputDelimited component, which is labeled Source, to display its Basic settings view where you can define the component properties.
The dynamic schema feature is only supported in Built-In mode and requires the input file to have a header row.
In the File name/Stream field, type in the path to the input file in double quotation marks, or browse to the path by clicking the [...] button.
In the Header field, type in 1 to use the first line of the file as the header.
Click the [...] button next to Edit schema to open the [Schema] dialog box.
Click the [+] button to add a column, give a name to the column, dyna in this example, and select Dynamic from the Type list. This dynamic column will retrieve the three columns, FirstName, LastName and Address, of the input file.
Click OK to validate the setting and close the dialog box.
Double-click the tFileOutputDelimited component, which is labeled Target, to display its Basic settings view where you can define the component properties.
Define the output file path in the File Name field.
Select the Include Header check box to include the header in the output file. Leave all the other settings are they are.
Double-click tJavaFlex to display its Basic settings view and define the components properties.
Click Sync columns to make sure that the schema is correctly retrieved from the preceding component.
In the Start code field, enter the following code:
System.out.println("Content of file being transferred:\n");
In the Main code field, enter the code to be applied on each line of data.
In this example, we want to display the content of the source file based on the defined dynamic schema column:
In the Main code field, "row1" refers to the name of the link that connects to tJavaFlex. If you rename this link, you have to modify the code.
In the End code field, enter the code that will be executed in the closing phase.
In this example, the code indicates the end of the execution of tJavaFlex by displaying the "End of file" message:
System.out.println("\nEnd of file");
Save your Job by pressing Ctrl+S.
Execute the Job by pressing F6 or clicking Run on the Run tab.
The console displays the content of the input file. As the Data Auto Propagate check box is selected by default, the content of the file is intactly transferred to the output component.