Skip to main content Skip to complementary content

Creating a user routine

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.
    Information noteNote: 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 Studio User Guide.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!