IBM Support

How to write a Byte Order Mark using the FileSystem Connector

Question & Answer


Question

In a case where a customer has chosen not to enable the 'Write header' option on the CSV Parser, the Byte Order Mark (BOM) will not be created even if 'Write BOM' is enabled.

Cause

The CSV Parser will add the BOM only when 'Write header', 'Write BOM', and 'Character Encoding' fields are all enabled in the advanced section of the Parser's configuration tab. In the case where a customer has chosen not to enable 'Write header', the customer will need to use script to manually create the BOM if desired.

Answer

To add the BOM to the output file when 'Write header' is not enabled:

1. Create a Resources > Scripts > New Script

2. Add the following function


    function writeBOM()
    {
    var fileName = thisConnector.connector.getParam("filePath");
    var sourceFile=new java.io.File(fileName);
    var bis = new java.io.BufferedInputStream(new java.io.FileInputStream(sourceFile), 4096);
    var ext = fileName.substring(fileName.lastIndexOf("." ),fileName.length())
    var targetFile = new java.io.File(fileName.replace(ext, "_bom"+ext));
    var bos = new java.io.BufferedOutputStream(new java.io.FileOutputStream(targetFile), 4096);
    var theChar=' ' ;

    // write hex characters - example of UTF-8 BOM
    bos.write(0xEF);
    bos.write(0xBB);
    bos.write(0xBF);

    while ((theChar = bis.read()) != -1) {
    bos.write(theChar);
    }

    // close source and target files
    bos.close();
    bis.close();
    }

3. Save the script

Within the AssemblyLine

4. Select Options > AssemblyLine Settings > Click the 'Select' button to Include Additional Prologs > Select the script created above. > OK to complete.

5. Enable the After_Close hook of the FileSystem Connector.

      Add the name of the function. In this example

        writeBOM()

[{"Product":{"code":"SSCQGF","label":"Tivoli Directory Integrator"},"Business Unit":{"code":"BU008","label":"Security"},"Component":"General","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"7.0;7.1;7.1.1;7.2","Edition":"All Editions","Line of Business":{"code":"LOB24","label":"Security Software"}}]

Document Information

Modified date:
16 June 2018

UID

swg21678542