Customer Portal

Writing raw data to an output port

Comments 2

  • Avatar
    jsinglet
    0
    Comment actions Permalink
    OK, I see now how to do it:

    			
    DataRecord record = DataRecordFactory.newRecord(metadata);
    record.getField(0).setValue(decrypted.toByteArray());

    writeRecordToPort(0, record);


    Where decrypted is a ByteArrayOutputStream where the decrypted data was written.
  • Avatar
    Lukas Cholasta
    0
    Comment actions Permalink
    Hi,

    The data you want to write to an output port has to have the form of a DataRecord. Every data flowing through a CloverETL graph has to be mapped to some metadata. This is the way you do it in a custom Java transformation. You don't have to parse the data yourself, you can create a metadata containing only one field of byte type and map your whole byte array to it. This way you can get the array to an edge and parse it by other components. The code may look like this:

    public void execute() {

    DataRecord record = outRecords[0];

    try (InputStream in = getInputStream("data-in/data2.txt")) {

    record.getField("field1").setValue(IOUtils.toByteArray(in));
    writeRecordToPort(0, record);

    } catch (IOException e) {
    throw new JetelRuntimeException("Problem with reading input file", e);
    }
    }


    The code reads data from a file and the "IOUtils.toByteArray(in)" is just a substitution of a byte[] array.

    Hope this helps.

Please sign in to leave a comment.