Author |
Message
|
MarkBitter |
Posted: Wed Aug 10, 2005 4:26 pm Post subject: How to read multi-byte messages into a Java string? |
|
|
Newbie
Joined: 10 Aug 2005 Posts: 4
|
I'm trying to read a message with multi-byte characters into a java string. (Unicode)
The characterset code received may be one of several (UTF-8, Big5, etc.)
Failed Code #1:
q.get( m, gmo );
String s = m.readString( m.getMessageLength() );
Failure: EOF Exception
[because MessageLength is in bytes, not characters]
Failed Code #2:
byte[] b =new byte[m.getDataLength()];
m.readFully(b);
String s = new String( b, m.characterSet );
[won't work, because m.characterSet is an int, not a String]
Note: It doesn't seem to matter whether I use the CONVERT option in GMO or not.
How can I generalize my read so it works for both single and multi-byte messages?
Thanks
Using MQ 5.3, Java 1.4.2 |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Aug 10, 2005 6:01 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
First of all the message needs to have the MQSTR format so that it is recognized as a text message.
Then make sure that the CCSID (character code set id) is recognised and translated correctly between source and target qmgr.
Then just use convert in the get options.
Enjoy  |
|
Back to top |
|
 |
MarkBitter |
Posted: Thu Aug 11, 2005 7:30 am Post subject: Still not working |
|
|
Newbie
Joined: 10 Aug 2005 Posts: 4
|
Format is set to String (MQSTR).
CCSID's are ok. If it wasn't recognized or translated, the exception would be different.
Problem occurs whether or not I use the convert option. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Aug 11, 2005 11:02 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Than read the message as bytes
and use java's own transformation features to create the String from the byte[] or ByteStream...
Remember you want V1.4 or > for java.nio
Enjoy  |
|
Back to top |
|
 |
MarkBitter |
Posted: Fri Aug 12, 2005 1:01 pm Post subject: |
|
|
Newbie
Joined: 10 Aug 2005 Posts: 4
|
fjb_saper wrote: |
Than read the message as bytes
and use java's own transformation features to create the String from the byte[] or ByteStream...
Remember you want V1.4 or > for java.nio
Enjoy  |
That's exactly what my code sample #2 does.
The problem is creating the java String requires a character set id (String),
but what I have is an MQ characterSet code (int).
I don't see how I can maintain a mapping table for all cases.
Enjoy  |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Aug 12, 2005 3:32 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
If you want not to have to worry about the bytes and bits why not try the JMS interface ?
That should give you back a string if a string was written when you use a TextMessage.
Enjoy  |
|
Back to top |
|
 |
MarkBitter |
Posted: Fri Aug 12, 2005 7:34 pm Post subject: |
|
|
Newbie
Joined: 10 Aug 2005 Posts: 4
|
fjb_saper wrote: |
If you want not to have to worry about the bytes and bits why not try the JMS interface ?
That should give you back a string if a string was written when you use a TextMessage.
Enjoy  |
I knew that was coming.  |
|
Back to top |
|
 |
|