ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » How to read multi-byte messages into a Java string?

Post new topic  Reply to topic
 How to read multi-byte messages into a Java string? « View previous topic :: View next topic » 
Author Message
MarkBitter
PostPosted: Wed Aug 10, 2005 4:26 pm    Post subject: How to read multi-byte messages into a Java string? Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Wed Aug 10, 2005 6:01 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
MarkBitter
PostPosted: Thu Aug 11, 2005 7:30 am    Post subject: Still not working Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Thu Aug 11, 2005 11:02 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
MarkBitter
PostPosted: Fri Aug 12, 2005 1:01 pm    Post subject: Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Fri Aug 12, 2005 3:32 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
MarkBitter
PostPosted: Fri Aug 12, 2005 7:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » How to read multi-byte messages into a Java string?
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.