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 » MQMessage.readFully()

Post new topic  Reply to topic
 MQMessage.readFully() « View previous topic :: View next topic » 
Author Message
brpope
PostPosted: Thu Aug 02, 2001 8:07 am    Post subject: Reply with quote

Novice

Joined: 01 Aug 2001
Posts: 10

The following code snippit illustrates a question I have about the behavior of the MQMessage.readFully() method. My test message size is 73 bytes.

If the buffer size is identical to the message size, the call works fine. If the buffer size is *larger* than the message size, the call throws an IOException EOF.
Unfortunetly, there isn't any additional data available from the exception and the docs don't elabroate.

Seems odd that a buffer that is too big causes a problem. Anybody seen this before? I'd really like to just allocate
a large buffer once it re-use it for various messages.

MQMessage newMsg;
....
byte[] buffer = new byte newMsg.getMessageLength()]; // works
byte[] buffer = new byte[1024]; // fails

newMsg.readFully(buffer);

IOException java.io.EOFException
exception.getMessage() returns null.

Thanks, Ben
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
kolban
PostPosted: Fri Aug 03, 2001 2:06 pm    Post subject: Reply with quote

Grand Master

Joined: 22 May 2001
Posts: 1072
Location: Fort Worth, TX, USA

Ben,
This is exactly as expected.

What follows is the spec of readFully from java.io.DataInput

readFully

public void readFully(byte[] b)
throws IOException


Reads some bytes from an input stream and stores them into the buffer array b. The number of bytes read is equal to the length of b.

This method blocks until one of the following conditions occurs:


· b.length bytes of input data are available, in which case a normal return is made.
· End of file is detected, in which case an EOFException is thrown.
· An I/O error occurs, in which case an IOException other than EOFException is thrown.


If b is null, a NullPointerException is thrown. If b.length is zero, then no bytes are read. Otherwise, the first byte read is stored into element b[0], the next one into b[1], and so on. If an exception is thrown from this method, then it may be that some but not all bytes of b have been updated with data from the input stream.

Parameters:

b - the buffer into which the data is read.

Throws:

EOFException - if this stream reaches the end before reading all the bytes.
IOException - if an I/O error occurs.

An MQMessage implements this interface. All is well
Back to top
View user's profile Send private message
bduncan
PostPosted: Fri Aug 03, 2001 2:15 pm    Post subject: Reply with quote

Padawan

Joined: 11 Apr 2001
Posts: 1554
Location: Silicon Valley

It would seem to me then that he could still use a very large buffer, and whenever it throws the EOF exception, just catch it and do nothing. The only thing that worries me however is the statement: "some but not all bytes of b have been updated with data from the input stream". Does this mean that if there is an EOF thrown, there really isn't any guarantee that everything up to the EOF is in the array? hmm...


_________________
Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator
Back to top
View user's profile Send private message Visit poster's website AIM Address
kolban
PostPosted: Fri Aug 03, 2001 3:25 pm    Post subject: Reply with quote

Grand Master

Joined: 22 May 2001
Posts: 1072
Location: Fort Worth, TX, USA

You shouldn't assume that the data in the buffer returned in readFully is useful if an exception is thrown. I think I question the idea of extracting the data in the first place or not allocating a specific buffer for what is wanted.

For example:

message.seek(0);
byte data[] = new byte[message.getMessageLength()];
message.readFully(data);

Will allocate a new buffer (data) for exactly the right length of data. If you must maintain a data buffer and want to read up-to the data buffer length then use the following readFully over-ride:

readFully
public void readFully(byte b [],
int off,
int len)
Throws IOException, EOFException.
Fill len elements of the byte array b with data from the message buffer,
starting at offset off.
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 » MQMessage.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.