#27 Problem with StreamMessage.readBytes

closed
Alwin Ibba
None
5
2008-06-27
2007-09-05
David Dossot
No

First thing: *thanks a lot* for this very useful project!
--

MockStreamMessage.readBytes is not implemented as specified in the API: http://java.sun.com/j2ee/1.4/docs/api/javax/jms/StreamMessage.html#readBytes\(byte[])

Let me explain: if the read buffer is smaller than the amount of bytes in the byte[] that was written to the stream message, subsequent calls return a MessageEOFException because the byte[] as been popped from the data stack, though not totally unread.

One way to fix this would be to push the remaining of the byte[] back to the stack.

Note that even an empty array would have to be pushed back because, as stated in the API: "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."

Discussion

  • Alwin Ibba
    Alwin Ibba
    2007-09-06

    • assigned_to: nobody --> aibba
     
  • Alwin Ibba
    Alwin Ibba
    2007-09-06

    Logged In: YES
    user_id=804648
    Originator: NO

    Yes you are right. Thanks for reporting this.

    "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."

    Because of this a pushed back empty array must lead to a -1 return value on the second call.

    But if the array is initially empty, the method must return 0:

    "If the byte array field value is empty, readBytes returns 0."

    The push back of empty arrays makes not really sense to me, but that's the spec so I'll implement it this way...

     
  • Alwin Ibba
    Alwin Ibba
    2008-06-27

    • status: open --> closed