Skip to Content
0
Nov 07, 2016 at 12:14 PM

HCI - Adding Byte Order Mark (BOM) to UTF-8 file content

4093 Views Last edit Nov 07, 2016 at 12:20 PM 3 rev

Dear Experts,

I'm trying to add BOM (Byte Order Mark) characters to UTF-8 file content thru Groovy script while sending file to 3rd party SFTP server.

  • Added CamelCharsetName with UTF-8 as Header parameter

  • In Groovy script, tried appending BOM with payload content
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;

def Message processData(Message message) {
            
        Map headerMap = message.getHeaders();
        def payload = message.getBody(java.lang.String);
        String bom = new String("\u00EF\u00BB\u00BF"); //"0xEF,0xBB,0xBF";
                
        //Add ByteOrderMark to payload
        payload = bom+payload;
        message.setBody(payload);
    
return message;
}

The file created at the target does not have correct BOM characters and failing in target. When examined the target file with Hex editor we can clearly see that the BOM is not correct (the same code in Groovy console is creating correct BOM so editors like Notepad & Notepad++ recognize correctly as UTF-8 with BOM).

Correct BOM & Text Content (expected) as viewed in -- HEX -- Mode

Correct BOM & Text Content (expected) as viewed in -- Normal -- Mode

Incorrect BOM (produced by HCI thru Groovy) in -- HEX -- Mode

Anybody experienced similar issue and found any work around to fix the issue?

Thanks in advance.

Ananth Chinnaraj

Attachments

camelcharset.jpg (50.0 kB)
correctbom.jpg (19.1 kB)
incorrectbom.jpg (24.7 kB)