You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by "John F. Lentz" <Jo...@ngc.com> on 2008/03/27 00:00:21 UTC

Strange StreamMessage problem

I can't find an answer to this question in the forum, so I appologize if it
has already been addressed.

I'm having a strange effect when using a stream message to transmit multiple
byte arrays in a single message.

My message consists of the following stream (short, byte[], int, byte[]). 
When I attempt to call StreamMessage.readBytes to get the second byte array
out of the stream it returns -1.  Reading the documentation it sounds like
that indicates that there is a null byte array in the stream.  If I then
attempt to the StreamMessage.readBytes call again I get the results that I'm
expecting.

If I send the following stream (short, int, byte[]) then I see the expected
behavior with that byte array.  Meaning that the first time I attempt to
read the byte[] out of the StreamMessage that it retrieves the array
succesfully.

Any idea what is going on?

Thanks,

John L.
-- 
View this message in context: http://www.nabble.com/Strange-StreamMessage-problem-tp16318501s2354p16318501.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Strange StreamMessage problem

Posted by Rob Davies <ra...@gmail.com>.
Great! thanks for explaining this to everyone John

cheers,

Rob
On 27 Mar 2008, at 20:42, John F. Lentz wrote:

>
> After looking at the documentation more closely I think I've  
> answered my own
> question, and that this behavior is by design.
>
> "To read the field value, readBytes should be successively called  
> until it
> returns a value less than the length of the read buffer. The value  
> of the
> bytes in the buffer following the last byte read is undefined.
>
> If readBytes returns a value equal to the length of the buffer, a  
> subsequent
> readBytes call must be made. If there are no more bytes to be read,  
> this
> call returns -1. "
>
> http://java.sun.com/j2ee/1.4/docs/api/javax/jms/StreamMessage.html#readBytes(byte 
> [])
> http://java.sun.com/j2ee/1.4/docs/api/javax/jms/StreamMessage.html#readBytes(byte 
> [])
>
> By those lines of documentation it looks like that -1 return value  
> is used
> as an indicator that the byte array has been fully read.  And  
> therefore even
> if the user knows the size of the byte array they should make  
> another call
> to the readBytes() method in order to clear out that indicator flag.
>
> John L.
>
>
> John F. Lentz wrote:
>>
>> I can't find an answer to this question in the forum, so I  
>> appologize if
>> it has already been addressed.
>>
>> I'm having a strange effect when using a stream message to transmit
>> multiple byte arrays in a single message.
>>
>> My message consists of the following stream (short, byte[], int,  
>> byte[]).
>> When I attempt to call StreamMessage.readBytes to get the second byte
>> array out of the stream it returns -1.  Reading the documentation it
>> sounds like that indicates that there is a null byte array in the  
>> stream.
>> If I then attempt to the StreamMessage.readBytes call again I get the
>> results that I'm expecting.
>>
>> If I send the following stream (short, int, byte[]) then I see the
>> expected behavior with that byte array.  Meaning that the first  
>> time I
>> attempt to read the byte[] out of the StreamMessage that it  
>> retrieves the
>> array succesfully.
>>
>> Any idea what is going on?
>>
>> Thanks,
>>
>> John L.
>>
>
> -- 
> View this message in context: http://www.nabble.com/Strange-StreamMessage-problem-tp16318501s2354p16333995.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Strange StreamMessage problem

Posted by "John F. Lentz" <Jo...@ngc.com>.
After looking at the documentation more closely I think I've answered my own
question, and that this behavior is by design.

"To read the field value, readBytes should be successively called until it
returns a value less than the length of the read buffer. The value of the
bytes in the buffer following the last byte read is undefined. 

If readBytes returns a value equal to the length of the buffer, a subsequent
readBytes call must be made. If there are no more bytes to be read, this
call returns -1. "

http://java.sun.com/j2ee/1.4/docs/api/javax/jms/StreamMessage.html#readBytes(byte[])
http://java.sun.com/j2ee/1.4/docs/api/javax/jms/StreamMessage.html#readBytes(byte[]) 

By those lines of documentation it looks like that -1 return value is used
as an indicator that the byte array has been fully read.  And therefore even
if the user knows the size of the byte array they should make another call
to the readBytes() method in order to clear out that indicator flag.

John L.


John F. Lentz wrote:
> 
> I can't find an answer to this question in the forum, so I appologize if
> it has already been addressed.
> 
> I'm having a strange effect when using a stream message to transmit
> multiple byte arrays in a single message.
> 
> My message consists of the following stream (short, byte[], int, byte[]). 
> When I attempt to call StreamMessage.readBytes to get the second byte
> array out of the stream it returns -1.  Reading the documentation it
> sounds like that indicates that there is a null byte array in the stream. 
> If I then attempt to the StreamMessage.readBytes call again I get the
> results that I'm expecting.
> 
> If I send the following stream (short, int, byte[]) then I see the
> expected behavior with that byte array.  Meaning that the first time I
> attempt to read the byte[] out of the StreamMessage that it retrieves the
> array succesfully.
> 
> Any idea what is going on?
> 
> Thanks,
> 
> John L.
> 

-- 
View this message in context: http://www.nabble.com/Strange-StreamMessage-problem-tp16318501s2354p16333995.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.