Creating a user routine - 7.0

Data Integration Job Examples

Version
7.0
Language
English (United States)
Product
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 ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Design and Development > Designing Jobs

Procedure

  1. In the Repository tree view, expand Code to display the Routines folder.
  2. Right-click Routines and select Create routine.
  3. The [New routine] dialog box opens. Enter its name, in this example MyRoutineDemo, a purpose and a description.
  4. Click Finish to close the dialog box.
    Note: The newly created routine appears in the Repository tree view, directly below the Routines node.

    The routine editor opens to reveal a model routine which contains a simple example, by default, comprising descriptive text in blue, followed by the corresponding code.

  5. Replace the model with the following code and press Ctrl+S to save the routine.

    It has a ByteArrayFromFile function, that requires a file path as input parameter and is used to read a file and convert it to a byte array.

    package routines;public class MyRoutineDemo {
    public static byte[] ByteArrayFromFile(String filepath) {
    try{ 
    java.io.File file=new java.io.File(filepath);
    java.io.FileInputStream fis = new java.io.FileInputStream(file);
    int fileLength = (int) file.length();
    byte[] incoming_file_data = new byte[fileLength]; // allocate byte array of right size
    fis.read(incoming_file_data, 0, fileLength ); // read into byte array
    fis.close();
    return incoming_file_data;
    }catch(Exception err){
    err.printStackTrace();return null;
    }
    }
    }

    For more information on how to create user routines, see the Talend User Guide on Talend Help Center.