[QFJ-282] FIXMessageEncoder#encode() may throws java.nio.BufferOverflowException if message contains Chinese characters Created: 27/Dec/07 Updated: 02/Apr/15 Resolved: 09/Jun/14 |
|
| Status: | Closed |
| Project: | QuickFIX/J |
| Component/s: | Engine |
| Affects Version/s: | 1.2.1 |
| Fix Version/s: | 1.6.0 |
| Type: | Bug | Priority: | Default |
| Reporter: | CaiQi | Assignee: | amichair |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | encoding | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
FIXMessageEncoder#encode() may throws protocol handler exception: java.nio.BufferOverflowException, if message contains Chinese characters. we use "UTF-8" as default charset instead of "ISO-8859-1". So charsetEncoding = "UTF-8". FIXMessageEncoder#encode() : catch (UnsupportedEncodingException e) { throw new ProtocolCodecException(e); }if message contains Chinese characters, fixMessageString.length() will not equal to fixMessageString.getBytes(charsetEncoding).length. Because A Chinese character will use "three" Bytes in "UTF-8". But in String, it's length is still "1". we let: byte[] src = fixMessageString.getBytes(charsetEncoding); solution: ByteBuffer buffer; catch (UnsupportedEncodingException e) { throw new ProtocolCodecException(e); } |
| Comments |
| Comment by Jan Amoyo [ 29/Apr/08 ] |
|
One can also use the CharsetEncoder in java.nio.charset: Charset charset = Charset.forName("UTF-8"); CharBuffer cb = CharBuffer.wrap("fixMessageString"); |
| Comment by Jay Walters [ 03/Feb/09 ] |
|
See |