Details
Description
Hi All, I add the code below into my quickfix app, hoping that it could send fix message with multibytes character, such as Chinese.
CharsetSupport.setCharset("GBK");
But I found it failed to send out the fix execution report and throws a BufferOverflowException in method encode of quickfix.mina.message.FIXMessageEncoder.
Below is the code fragment in method encode:
ByteBuffer buffer = ByteBuffer.allocate(fixMessageString.length());
try
catch (UnsupportedEncodingException e)
{ throw new ProtocolCodecException(e); }BufferOverflowException is thrown by the code "buffer.put".
The reason is String.length() only return the count of character. For multibytes char, String.length() is half smaller than String.getBytes().length, so the capacity of ByteBuffer is not sufficient for the encoded bytes of the fixMessageString.
Although there is rarely multibytes char in fix message, it can be improved like the below:
ByteBuffer buffer = null;
try { byte[] encodedBytes = fixMessageString.getBytes(charsetEncoding) buffer = ByteBuffer.allocate(encodedBytes.length); buffer.put(encodedBytes); } catch (UnsupportedEncodingException e) { throw new ProtocolCodecException(e); }