ユーザールーチンを作成する - 7.3

データ統合ジョブの例

Version
7.3
Language
日本語
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 Real-Time Big Data Platform
Module
Talend Studio
Content
ジョブデザインと開発 > ジョブデザイン
Last publication date
2024-02-13

手順

  1. [Repository] (リポジトリー)ツリービューで、[Code] (コード)を展開し、[Routines] (ルーチン)を表示します。
  2. [Routines] (ルーチン)を右クリックし、[Create routine] (ルーチンの作成)を選択します。
  3. [New routine] (新規ルーチン)ダイアログボックスが開きます。名前(この例ではMyRoutineDemo)、目的、説明を入力します。
  4. [Finish] (終了)をクリックしてダイアログボックスを閉じます。
    注: 作成したばかりのルーチンが、[Repository] (リポジトリー)ツリービューの[Routines] (ルーチン)ノードのすぐ下に表示されます。

    ルーチンエディターが開き、デフォルトでモデルルーチンが示されます。これには、青色の説明文と対応するコードで構成される単純な例が含まれます。

  5. モデルを次のコードに置き換え、[Ctrl] + [S]を押してルーチンを保存します。

    このルーチンにはByteArrayFromFile関数が含まれています。この関数は入力パラメーターとしてファイルパスを必要とし、ファイルを読み取ってバイト配列に変換するために使われます。

    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;
    }
    }
    }

    ユーザールーチンの作成方法の詳細は、Talend Studioユーザーガイドをご覧ください。