CoralFIX FAQ

Below some frequently asked questions about CoralFIX.

  1. How to get string values from a FIX message without producing garbage?
    You can simply call getCharSequence(FixTag). CoralFIX maintains a StringBuilder pool under-the-hood and will always return a different instance with the string contents as a CharSequence. Just keep in mind that the pool is reset on every new FIX message, in other words, the StringBuilders from the pool will be re-used/overwritten on the following FIX message received. Therefore, although that’s seldom the use-case, if you need to store/save the string value across multiple FIX messages you must copy the contents from the CharSequence returned to somewhere else.
  2. Can I get string values as a byte array so I can use them as keys to a ByteArrayMap?
    Yes! Below an example:

    // first write a space (' ') to all bytes of the byte array
    ByteArrayUtils.clear(orderIdByteArray);
    
    // read the string value into the byte array
    int orderIdLength = fixMsg.readBytes(FixTags.OrderID, orderIdByteArray);
    
    if (orderIdLength <= 0) {
        // OrderID tag not present... nothing was read...
    } else {
        // use the byte array as the key to a ByteArrayMap
        Order order = orderByteArrayMap.get(orderIdByteArray);
        // (...)
    }