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 » writeUTF and readFully

Post new topic  Reply to topic
 writeUTF and readFully « View previous topic :: View next topic » 
Author Message
csdenis
PostPosted: Mon Dec 02, 2002 3:23 am    Post subject: writeUTF and readFully Reply with quote

Novice

Joined: 06 Oct 2002
Posts: 24

Dear all,

I've got a problem about writeUTF method.
I use writeUTF to write an MQ message in UTF-8 format. When I try to read it back, I use readUTF and the result is perfect. However, when I use readfully to read it into an byte array and contruct it into string using

String sth = new String(myByteArray, "UTF8")

the first 2 bytes of the string are strange characters. I know it is the length in UTF-8, but can I got the exact string using writeUTF and readFully?

Thanks to all.
Back to top
View user's profile Send private message
nimconsult
PostPosted: Tue Dec 03, 2002 12:00 am    Post subject: Reply with quote

Master

Joined: 22 May 2002
Posts: 268
Location: NIMCONSULT - Belgium

The readFully() reads the message data, including string length and string contents. The String(byte[], String) constructor does not expect a string length at the beginning of the bytes array.

One possible option is to call m.skipBytes(2) before the m.readFully(...).

My test sample:

Code:
byte[] b = new byte[m.getDataLength() - 2];
m.skipBytes(2);
m.readFully(b);
String s = new String(b, "UTF8");
System.out.println(s);


Of course readUTF is easier to use than the previous code sample. But this sample answers your question.

Nicolas
_________________
Nicolas Maréchal
Senior Architect - Partner

NIMCONSULT Software Architecture Services (Belgium)
http://www.nimconsult.be
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » writeUTF and readFully
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.