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 » Question about readLine

Post new topic  Reply to topic
 Question about readLine « View previous topic :: View next topic » 
Author Message
nzr1949
PostPosted: Fri Jul 22, 2005 12:48 am    Post subject: Question about readLine Reply with quote

Novice

Joined: 16 Nov 2004
Posts: 15

Hi,

I've placed a text file onto a queue and would like to read the contents of the file back off the queue and then write them to a text file. I'm using the readLine() method to read one line of the message at a time. The problem I'm having is that I can't detect when the end of the message has been reached. Portion of code is below:

Code:

MQMessage m = new MQMessage();
m.format = MQC.MQFMT_NONE;

MQMessage msg = new MQMessage();
MQGetMessageOptions ops = new MQGetMessageOptions();
ops.options = MQC.MQGMO_BROWSE_FIRST;              

msg.clearMessage();
msg.correlationId = MQC.MQCI_NONE;
msg.messageId = MQC.MQMI_NONE;
         
// read the message without removing it
this.myQueue.get(msg, ops);
         
String line = "";
         
while (line = msg.readLine()) != null)
{
    System.out.println(line);
}


When this code runs and reaches the while loop it becomes infinite and never ends, it prints the contents of the text file correctly but as soon as it reaches the end of the text file is starts printing empty strings. I have consulted the MQ Java manual and it doesn't state what value the readLine() method returns when it has reached the end of a text file. Surely it is null as I have it in the code above?

Thanks,
Ramsey
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri Jul 22, 2005 3:40 am    Post subject: Re: Question about readLine Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

nzr1949 wrote:
while (line = msg.readLine()) != null)


Your parentheses are not right.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
nzr1949
PostPosted: Fri Jul 22, 2005 7:44 am    Post subject: Reply with quote

Novice

Joined: 16 Nov 2004
Posts: 15

Sorry, that was a typo, it should read:

Code:

while ((line = msg.readLine()) != null)


I'm still stumped, how do you detect the last line in the message?
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Fri Jul 22, 2005 7:52 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I'm going to guess that your message doesn't end with any of the terminators mentioned in
Using Java wrote:
readLine

public String readLine() throws IOException;
Reads a line of text from the message. Converts from the codeset identified in characterSet, and then reads in a line that has been terminated by \n, \r, \r\n, EOF or the end of a UTF string.

_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
amitaborker
PostPosted: Wed Jul 27, 2005 4:12 am    Post subject: Try this Reply with quote

Newbie

Joined: 27 Jul 2005
Posts: 1
Location: Bangalore

while (msgToRead.getDataLength()>0)
{
System.out.println(msgToRead.readLine());
}
Back to top
View user's profile Send private message Yahoo Messenger
nzr1949
PostPosted: Wed Jul 27, 2005 4:31 am    Post subject: Reply with quote

Novice

Joined: 16 Nov 2004
Posts: 15

That works like a charm.

Thanks!
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 » Question about readLine
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.